Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional metadata to service #1170

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions micro/service.go
Expand Up @@ -57,11 +57,15 @@ type (
// It should return a value which can be serialized to JSON.
StatsHandler func(Endpoint) interface{}

// Metadata allows to add optional metadatas to ServiceIdentity
Metadata map[string]interface{}

// ServiceIdentity contains fields helping to identidy a service instance.
ServiceIdentity struct {
Name string `json:"name"`
ID string `json:"id"`
Version string `json:"version"`
Name string `json:"name"`
ID string `json:"id"`
Version string `json:"version"`
Meta Metadata `json:"meta,omitempty"`
}

// Stats is the type returned by STATS monitoring endpoint.
Expand Down Expand Up @@ -116,6 +120,7 @@ type (
Description string `json:"description"`
Schema Schema `json:"schema"`
Endpoint Endpoint `json:"endpoint"`
Meta Metadata `json:"meta,omitempty"`
StatsHandler StatsHandler
DoneHandler DoneHandler
ErrorHandler ErrHandler
Expand Down Expand Up @@ -237,6 +242,7 @@ func AddService(nc *nats.Conn, config Config) (Service, error) {
Name: config.Name,
ID: id,
Version: config.Version,
Meta: config.Meta,
}
svc.verbSubs = make(map[string]*nats.Subscription)
svc.stats = &Stats{
Expand Down Expand Up @@ -523,6 +529,7 @@ func (s *service) Info() Info {
Name: s.Config.Name,
ID: s.id,
Version: s.Config.Version,
Meta: s.Config.Meta,
},
Description: s.Config.Description,
Subject: s.Config.Endpoint.Subject,
Expand All @@ -542,6 +549,7 @@ func (s *service) Stats() Stats {
Name: info.Name,
ID: info.ID,
Version: info.Version,
Meta: s.Config.Meta,
},
NumRequests: s.stats.NumRequests,
NumErrors: s.stats.NumErrors,
Expand Down
3 changes: 2 additions & 1 deletion micro/service_test.go
Expand Up @@ -441,7 +441,8 @@ func TestAddService(t *testing.T) {
}

test.expectedPing.ID = info.ID
if test.expectedPing != ping {
//if test.expectedPing != ping {
if !reflect.DeepEqual(test.expectedPing, ping) {
t.Fatalf("Invalid ping response; want: %+v; got: %+v", test.expectedPing, ping)
}

Expand Down