Skip to content

Commit

Permalink
Rename "micro" to "service" with a compatability alias
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <rip@devco.net>
  • Loading branch information
ripienaar committed Nov 16, 2023
1 parent 1a9262f commit dba0635
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
53 changes: 26 additions & 27 deletions cli/service_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/nats-io/nats.go/micro"
)

type microCmd struct {
type serviceCmd struct {
name string
id string
showJSON bool
Expand All @@ -40,39 +40,38 @@ type microCmd struct {
nc *nats.Conn
}

func configureMicroCommand(app commandHost) {
c := &microCmd{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{}
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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())
}
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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))

Check failure on line 466 in cli/service_command.go

View workflow job for this annotation

GitHub Actions / test (1.20)

fmt.Sprintf format %S has unknown verb S

Check failure on line 466 in cli/service_command.go

View workflow job for this annotation

GitHub Actions / test (1.21)

fmt.Sprintf format %S has unknown verb S
}
table.AddHeaders("Name", "Version", "ID", "Description")
var pd, pv, pn string
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ 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
github.com/gosuri/uiprogress v0.0.1
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
github.com/prometheus/client_golang v1.17.0
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
)

Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down

0 comments on commit dba0635

Please sign in to comment.