MCPcopy
hub / github.com/nats-io/nats.go / ExampleService_AddGroup

Function ExampleService_AddGroup

micro/example_test.go:123–151  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

121}
122
123func ExampleService_AddGroup() {
124 nc, err := nats.Connect("127.0.0.1:4222")
125 if err != nil {
126 log.Fatal(err)
127 }
128 defer nc.Close()
129
130 echoHandler := func(req micro.Request) {
131 req.Respond(req.Data())
132 }
133
134 config := micro.Config{
135 Name: "EchoService",
136 Version: "1.0.0",
137 }
138
139 srv, err := micro.AddService(nc, config)
140 if err != nil {
141 log.Fatal(err)
142 }
143
144 v1 := srv.AddGroup("v1")
145
146 // endpoint will be registered under "v1.Echo" subject
147 err = v1.AddEndpoint("Echo", micro.HandlerFunc(echoHandler))
148 if err != nil {
149 log.Fatal(err)
150 }
151}
152
153func ExampleService_Info() {
154 nc, err := nats.Connect("127.0.0.1:4222")

Callers

nothing calls this directly

Calls 8

AddServiceFunction · 0.92
HandlerFuncFuncType · 0.92
ConnectMethod · 0.80
RespondMethod · 0.65
DataMethod · 0.65
AddGroupMethod · 0.65
AddEndpointMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected