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

[ADDED] Support for multi-endpoint services #1180

Merged
merged 6 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add handling empty groups
  • Loading branch information
piotrpio committed Jan 11, 2023
commit 7ce2839ec4402c6a36b9abde04295fbc628e11f1
18 changes: 15 additions & 3 deletions micro/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,14 +746,26 @@ func (g *group) AddEndpoint(name string, handler Handler, opts ...EndpointOpt) e
if options.subject != "" {
subject = options.subject
}
subject = fmt.Sprintf("%s.%s", g.prefix, subject)
return addEndpoint(g.service, name, subject, handler)
endpointSubject := fmt.Sprintf("%s.%s", g.prefix, subject)
if g.prefix == "" {
endpointSubject = subject
}
return addEndpoint(g.service, name, endpointSubject, handler)
}

func (g *group) AddGroup(name string) Group {
parts := make([]string, 0, 2)
if g.prefix != "" {
parts = append(parts, g.prefix)
}
if name != "" {
parts = append(parts, name)
}
prefix := strings.Join(parts, ".")

return &group{
service: g.service,
prefix: fmt.Sprintf("%s.%s", g.prefix, name),
prefix: prefix,
}
}

Expand Down
12 changes: 12 additions & 0 deletions micro/test/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,18 @@ func TestGroups(t *testing.T) {
groups: []string{"g1"},
expectedSubject: "g1.foo",
},
{
name: "single empty group",
endpointName: "foo",
groups: []string{""},
expectedSubject: "foo",
},
{
name: "empty groups",
endpointName: "foo",
groups: []string{"", "g1", ""},
expectedSubject: "g1.foo",
},
{
name: "multiple groups",
endpointName: "foo",
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy