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

Function ControlSubject

micro/service.go:937–952  ·  view source on GitHub ↗

ControlSubject returns monitoring subjects used by the Service. Providing a verb is mandatory (it should be one of Ping, Info or Stats). Depending on whether kind and id are provided, ControlSubject will return one of the following: - verb only: subject used to monitor all available services - verb

(verb Verb, name, id string)

Source from the content-addressed store, hash-verified

935// - verb and kind: subject used to monitor services with the provided name
936// - verb, name and id: subject used to monitor an instance of a service with the provided ID
937func ControlSubject(verb Verb, name, id string) (string, error) {
938 verbStr := verb.String()
939 if verbStr == "" {
940 return "", fmt.Errorf("%w: %q", ErrVerbNotSupported, verbStr)
941 }
942 if name == "" && id != "" {
943 return "", ErrServiceNameRequired
944 }
945 if name == "" && id == "" {
946 return fmt.Sprintf("%s.%s", APIPrefix, verbStr), nil
947 }
948 if id == "" {
949 return fmt.Sprintf("%s.%s.%s", APIPrefix, verbStr, name), nil
950 }
951 return fmt.Sprintf("%s.%s.%s.%s", APIPrefix, verbStr, name, id), nil
952}
953
954func WithEndpointSubject(subject string) EndpointOpt {
955 return func(e *endpointOpts) error {

Callers 5

ExampleControlSubjectFunction · 0.92
TestServiceBasicsFunction · 0.92
TestAddServiceFunction · 0.92
TestControlSubjectFunction · 0.92
addInternalHandlerMethod · 0.85

Calls 2

ErrorfMethod · 0.80
StringMethod · 0.45

Tested by 4

ExampleControlSubjectFunction · 0.74
TestServiceBasicsFunction · 0.74
TestAddServiceFunction · 0.74
TestControlSubjectFunction · 0.74