Skip to content

Commit 0f55346

Browse files
committed
feat: support multiple tags
1 parent 3fa479d commit 0f55346

File tree

5 files changed

+45
-44
lines changed

5 files changed

+45
-44
lines changed

consul.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (r *resolvr) Close() {
3333

3434
//go:generate ./bin/moq -out mocks_test.go . servicer
3535
type servicer interface {
36-
Service(string, string, bool, *api.QueryOptions) ([]*api.ServiceEntry, *api.QueryMeta, error)
36+
ServiceMultipleTags(string, []string, bool, *api.QueryOptions) ([]*api.ServiceEntry, *api.QueryMeta, error)
3737
}
3838

3939
func watchConsulService(ctx context.Context, s servicer, tgt target, out chan<- []string) {
@@ -48,9 +48,9 @@ func watchConsulService(ctx context.Context, s servicer, tgt target, out chan<-
4848
go func() {
4949
var lastIndex uint64
5050
for {
51-
ss, meta, err := s.Service(
51+
ss, meta, err := s.ServiceMultipleTags(
5252
tgt.Service,
53-
tgt.Tag,
53+
tgt.Tags,
5454
tgt.Healthy,
5555
&api.QueryOptions{
5656
WaitIndex: lastIndex,

consul_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestWatchConsulService(t *testing.T) {
6262
errorFromService error
6363
want []string
6464
}{
65-
{"simple", target{Service: "svc", Wait: time.Second},
65+
{"simple", target{Service: "svc", Tags: []string{"foo", "bar"}, Wait: time.Second},
6666
[]*api.ServiceEntry{
6767
{
6868
Service: &api.AgentService{Address: "127.0.0.1", Port: 1024},
@@ -92,9 +92,9 @@ func TestWatchConsulService(t *testing.T) {
9292
}
9393
}()
9494
fconsul := &servicerMock{
95-
ServiceFunc: func(s1, s2 string, b bool, queryOptions *api.QueryOptions) ([]*api.ServiceEntry, *api.QueryMeta, error) {
95+
ServiceMultipleTagsFunc: func(s1 string, s2 []string, b bool, queryOptions *api.QueryOptions) ([]*api.ServiceEntry, *api.QueryMeta, error) {
9696
require.Equal(t, tt.tgt.Service, s1)
97-
require.Equal(t, tt.tgt.Tag, s2)
97+
require.Equal(t, tt.tgt.Tags, s2)
9898
require.Equal(t, tt.tgt.Healthy, b)
9999
require.Equal(t, tt.tgt.Near, queryOptions.Near)
100100
require.Equal(t, tt.tgt.Wait, queryOptions.WaitTime)

mocks_test.go

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

target.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type target struct {
2020
Wait time.Duration `form:"wait"`
2121
Timeout time.Duration `form:"timeout"`
2222
MaxBackoff time.Duration `form:"max-backoff"`
23-
Tag string `form:"tag"`
23+
Tags []string `form:"tag"`
2424
Near string `form:"near"`
2525
Limit int `form:"limit"`
2626
Healthy bool `form:"healthy"`
@@ -34,10 +34,11 @@ type target struct {
3434
}
3535

3636
func (t *target) String() string {
37-
return fmt.Sprintf("service='%s' healthy='%t' tag='%s'", t.Service, t.Healthy, t.Tag)
37+
return fmt.Sprintf("service='%s' healthy='%t' tag='%+v'", t.Service, t.Healthy, t.Tags)
3838
}
3939

40-
// parseURL with parameters
40+
// parseURL with parameters
41+
//
4142
// see README.md for the actual format
4243
// URL schema will stay stable in the future for backward compatibility
4344
func parseURL(u string) (target, error) {

target_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Test_parseURL(t *testing.T) {
2424
},
2525
false,
2626
},
27-
{"all-args", "consul://user:password@127.0.0.127:8555/my-service?wait=14s&near=host&insecure=true&limit=1&tag=production&token=test_token&max-backoff=2s&dc=xx&allow-stale=true&require-consistent=true",
27+
{"all-args", "consul://user:password@127.0.0.127:8555/my-service?wait=14s&near=host&insecure=true&limit=1&tag=production&tag=extra_tag&token=test_token&max-backoff=2s&dc=xx&allow-stale=true&require-consistent=true",
2828
target{
2929
Addr: "127.0.0.127:8555",
3030
User: "user",
@@ -34,7 +34,7 @@ func Test_parseURL(t *testing.T) {
3434
Wait: 14 * time.Second,
3535
TLSInsecure: true,
3636
Limit: 1,
37-
Tag: "production",
37+
Tags: []string{"production", "extra_tag"},
3838
Token: "test_token",
3939
MaxBackoff: 2 * time.Second,
4040
Dc: "xx",

0 commit comments

Comments
 (0)