diff --git a/cli/service_command.go b/cli/service_command.go index 382ac5e7..29496c5a 100644 --- a/cli/service_command.go +++ b/cli/service_command.go @@ -31,7 +31,7 @@ import ( "github.com/nats-io/nats.go/micro" ) -type microCmd struct { +type serviceCmd struct { name string id string showJSON bool @@ -40,39 +40,38 @@ type microCmd struct { nc *nats.Conn } -func configureMicroCommand(app commandHost) { - c := µCmd{hdrs: map[string]string{}} +func configureServiceCommand(app commandHost) { + c := &serviceCmd{hdrs: map[string]string{}} - mc := app.Command("micro", "Micro Services discovery and management").Alias("a") - mc.HelpLong("WARNING: This command is experimental") + mc := app.Command("service", "Services discovery and management").Alias("micro") - ls := mc.Command("list", "List known Micro services").Alias("ls").Alias("l").Action(c.listAction) - ls.Arg("service", "List instances of a specific service").PlaceHolder("NAME").StringVar(&c.name) + ls := mc.Command("list", "List known Services").Alias("ls").Alias("l").Action(c.listAction) + ls.Arg("service", "List instances of a specific Service").PlaceHolder("NAME").StringVar(&c.name) ls.Flag("json", "Show JSON output").Short('j').UnNegatableBoolVar(&c.showJSON) - info := mc.Command("info", "Show Micro service information").Alias("i").Action(c.infoAction) + info := mc.Command("info", "Show Service information").Alias("i").Action(c.infoAction) info.Arg("service", "Service to show").Required().StringVar(&c.name) info.Arg("id", "Show info for a specific ID").StringVar(&c.id) info.Flag("json", "Show JSON output").Short('j').UnNegatableBoolVar(&c.showJSON) - stats := mc.Command("stats", "Report Micro service statistics").Action(c.statsAction) + stats := mc.Command("stats", "Report Service statistics").Action(c.statsAction) stats.Arg("service", "Service to show").Required().StringVar(&c.name) stats.Arg("id", "Show info for a specific ID").StringVar(&c.id) stats.Flag("json", "Show JSON output").Short('j').UnNegatableBoolVar(&c.showJSON) - ping := mc.Command("ping", "Sends a ping to all services").Action(c.pingAction) + ping := mc.Command("ping", "Sends a ping to all Services").Action(c.pingAction) ping.Arg("service", "Service to show").StringVar(&c.name) - echo := mc.Command("serve", "Runs a demo Micro service").Action(c.serveAction) + echo := mc.Command("serve", "Runs a demo Service").Action(c.serveAction) echo.Arg("name", "A name for the service to run on").Required().StringVar(&c.name) echo.Flag("header", "Headers to add to responses").Short('H').StringMapVar(&c.hdrs) } func init() { - registerCommand("micro", 0, configureMicroCommand) + registerCommand("service", 0, configureServiceCommand) } -func (c *microCmd) echoHandler(req micro.Request) { +func (c *serviceCmd) echoHandler(req micro.Request) { log.Printf("Handling request on subject %v", req.Subject()) hdr := nats.Header{} @@ -97,7 +96,7 @@ func (c *microCmd) echoHandler(req micro.Request) { req.Respond(req.Data(), micro.WithHeaders(micro.Headers(hdr))) } -func (c *microCmd) serveAction(_ *fisk.ParseContext) error { +func (c *serviceCmd) serveAction(_ *fisk.ParseContext) error { var err error var combinedPayload int var mu sync.Mutex @@ -140,7 +139,7 @@ func (c *microCmd) serveAction(_ *fisk.ParseContext) error { return err } - cols := newColumns("NATS CLI Micro Service %s handler %d waiting for requests on %s", c.name, os.Getpid(), c.nc.ConnectedUrlRedacted()) + cols := newColumns("NATS CLI Service %s handler %d waiting for requests on %s", c.name, os.Getpid(), c.nc.ConnectedUrlRedacted()) cols.AddSectionTitle("Listening Subjects") cols.AddRow(fmt.Sprintf("%s.echo", c.name), "Echo Service") if len(c.hdrs) > 0 { @@ -157,7 +156,7 @@ func (c *microCmd) serveAction(_ *fisk.ParseContext) error { return nil } -func (c *microCmd) makeSubj(v micro.Verb, s string, i string) string { +func (c *serviceCmd) makeSubj(v micro.Verb, s string, i string) string { if s == "" { return fmt.Sprintf("%s.%s", micro.APIPrefix, v.String()) } @@ -169,7 +168,7 @@ func (c *microCmd) makeSubj(v micro.Verb, s string, i string) string { return fmt.Sprintf("%s.%s.%s.%s", micro.APIPrefix, v.String(), s, i) } -func (c *microCmd) parseMessage(m []byte, expectedType string) (any, error) { +func (c *serviceCmd) parseMessage(m []byte, expectedType string) (any, error) { var ( t string parsed any @@ -192,7 +191,7 @@ func (c *microCmd) parseMessage(m []byte, expectedType string) (any, error) { return parsed, nil } -func (c *microCmd) getInstanceStats(nc *nats.Conn, name string, id string) (*micro.Stats, error) { +func (c *serviceCmd) getInstanceStats(nc *nats.Conn, name string, id string) (*micro.Stats, error) { resp, err := doReq(nil, c.makeSubj(micro.StatsVerb, name, id), 1, nc) if err != nil { if errors.Is(err, nats.ErrNoResponders) { @@ -213,11 +212,11 @@ func (c *microCmd) getInstanceStats(nc *nats.Conn, name string, id string) (*mic return stats.(*micro.Stats), err } -func (c *microCmd) getInfo(nc *nats.Conn, name string, id string, wait int) ([]*micro.Info, error) { +func (c *serviceCmd) getInfo(nc *nats.Conn, name string, id string, wait int) ([]*micro.Info, error) { resp, err := doReq(nil, c.makeSubj(micro.InfoVerb, name, id), wait, nc) if err != nil { if errors.Is(err, nats.ErrNoResponders) { - return nil, fmt.Errorf("no micro instances found") + return nil, fmt.Errorf("no service instances found") } return nil, err } @@ -242,7 +241,7 @@ func (c *microCmd) getInfo(nc *nats.Conn, name string, id string, wait int) ([]* return nfos, nil } -func (c *microCmd) pingAction(_ *fisk.ParseContext) error { +func (c *serviceCmd) pingAction(_ *fisk.ParseContext) error { nc, _, err := prepareHelper("", natsOpts()...) if err != nil { return fmt.Errorf("setup failed: %v", err) @@ -279,7 +278,7 @@ func (c *microCmd) pingAction(_ *fisk.ParseContext) error { return nil } -func (c *microCmd) statsAction(_ *fisk.ParseContext) error { +func (c *serviceCmd) statsAction(_ *fisk.ParseContext) error { nc, _, err := prepareHelper("", natsOpts()...) if err != nil { return fmt.Errorf("setup failed: %v", err) @@ -288,7 +287,7 @@ func (c *microCmd) statsAction(_ *fisk.ParseContext) error { resp, err := doReq(nil, c.makeSubj(micro.StatsVerb, c.name, c.id), 0, nc) if err != nil { if errors.Is(err, nats.ErrNoResponders) { - return fmt.Errorf("no micro instances found") + return fmt.Errorf("no service instances found") } return err @@ -352,7 +351,7 @@ func (c *microCmd) statsAction(_ *fisk.ParseContext) error { return nil } -func (c *microCmd) infoAction(_ *fisk.ParseContext) error { +func (c *serviceCmd) infoAction(_ *fisk.ParseContext) error { nc, _, err := prepareHelper("", natsOpts()...) if err != nil { return fmt.Errorf("setup failed: %v", err) @@ -439,7 +438,7 @@ func (c *microCmd) infoAction(_ *fisk.ParseContext) error { return nil } -func (c *microCmd) listAction(_ *fisk.ParseContext) error { +func (c *serviceCmd) listAction(_ *fisk.ParseContext) error { nc, _, err := prepareHelper("", natsOpts()...) if err != nil { return fmt.Errorf("setup failed: %v", err) @@ -462,9 +461,9 @@ func (c *microCmd) listAction(_ *fisk.ParseContext) error { var table *tbl if c.name == "" { - table = newTableWriter("All Micro Services") + table = newTableWriter("All Services") } else { - table = newTableWriter(fmt.Sprintf("%s Micro Service", c.name)) + table = newTableWriter(fmt.Sprintf("%S Service Instances", c.name)) } table.AddHeaders("Name", "Version", "ID", "Description") var pd, pv, pn string diff --git a/go.mod b/go.mod index 5b184757..8d67d932 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/choria-io/fisk v0.6.1 github.com/dustin/go-humanize v1.0.1 github.com/emicklei/dot v1.6.0 - github.com/fatih/color v1.15.0 + github.com/fatih/color v1.16.0 github.com/ghodss/yaml v1.0.0 github.com/google/go-cmp v0.6.0 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 @@ -17,11 +17,11 @@ require ( github.com/guptarohit/asciigraph v0.5.6 github.com/jedib0t/go-pretty/v6 v6.4.9 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 - github.com/klauspost/compress v1.17.2 + github.com/klauspost/compress v1.17.3 github.com/mattn/go-isatty v0.0.20 github.com/nats-io/jsm.go v0.1.1-0.20231106122128-a65f417ea9e5 github.com/nats-io/jwt/v2 v2.5.3 - github.com/nats-io/nats-server/v2 v2.10.4-0.20231105183438-0b5d9c636cab + github.com/nats-io/nats-server/v2 v2.10.5 github.com/nats-io/nats.go v1.31.0 github.com/nats-io/nkeys v0.4.6 github.com/nats-io/nuid v1.0.1 @@ -29,8 +29,8 @@ require ( github.com/prometheus/common v0.45.0 github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 github.com/tylertreat/hdrhistogram-writer v0.0.0-20210816161836-2e440612a39f - golang.org/x/crypto v0.14.0 - golang.org/x/term v0.13.0 + golang.org/x/crypto v0.15.0 + golang.org/x/term v0.14.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -46,7 +46,7 @@ require ( github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/net v0.18.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.4.0 // indirect diff --git a/go.sum b/go.sum index 17d26767..8814eb74 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,8 @@ github.com/emicklei/dot v1.6.0 h1:vUzuoVE8ipzS7QkES4UfxdpCwdU2U97m2Pb2tQCoYRY= github.com/emicklei/dot v1.6.0/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -55,6 +57,8 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNU github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.3 h1:qkRjuerhUU1EmXLYGkSH6EZL+vPSxIrYjLNAK4slzwA= +github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -70,6 +74,7 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= @@ -83,6 +88,8 @@ github.com/nats-io/jwt/v2 v2.5.3 h1:/9SWvzc6hTfamcgXJ3uYRpgj+QuY2aLNqRiqrKcrpEo= github.com/nats-io/jwt/v2 v2.5.3/go.mod h1:iysuPemFcc7p4IoYots3IuELSI4EDe9Y0bQMe+I3Bf4= github.com/nats-io/nats-server/v2 v2.10.4-0.20231105183438-0b5d9c636cab h1:EMmEyTqqr1ba5f5DEeFPhdbcF41ZYcqEAVlOJ0/kDKc= github.com/nats-io/nats-server/v2 v2.10.4-0.20231105183438-0b5d9c636cab/go.mod h1:eWm2JmHP9Lqm2oemB6/XGi0/GwsZwtWf8HIPUsh+9ns= +github.com/nats-io/nats-server/v2 v2.10.5 h1:hhWt6m9ja/mNnm6ixc85jCthDaiUFPaeJI79K/MD980= +github.com/nats-io/nats-server/v2 v2.10.5/go.mod h1:xUMTU4kS//SDkJCSvFwN9SyJ9nUuLhSkzB/Qz0dvjjg= github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E= github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8= github.com/nats-io/nkeys v0.4.6 h1:IzVe95ru2CT6ta874rt9saQRkWfe2nFj1NtvYSLqMzY= @@ -122,6 +129,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -140,6 +149,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -160,6 +171,8 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8= +golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=