Skip to content

Commit 23f91ce

Browse files
committed
Add DefaultGRPCPort and use it in DNSTargetDiscoverer.
1 parent 14130ae commit 23f91ce

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@ The format is based on [Keep a Changelog], and this project adheres to
99
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
1010
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
1111

12+
## [0.1.1] - 2021-01-20
13+
14+
### Added
15+
16+
- Add `DefaultGRPCPort` constant
17+
18+
### Changed
19+
20+
- `DNSTargetDiscoverer` now uses `DefaultGRPCPort` by default
21+
1222
## [0.1.0] - 2021-01-20
1323

1424
- Initial release
1525

1626
<!-- references -->
1727
[Unreleased]: https://github.com/dogmatiq/discoverkit
1828
[0.1.0]: https://github.com/dogmatiq/discoverkit/releases/tag/v0.1.0
29+
[0.1.1]: https://github.com/dogmatiq/discoverkit/releases/tag/v0.1.1
1930

2031
<!-- version template
2132
## [0.0.1] - YYYY-MM-DD

dns.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type DNSTargetDiscoverer struct {
3131
// an IP address.
3232
//
3333
// If NewTargets is nil the discoverer constructs a single Target for each
34-
// discovered address. The target name is the discovered address and no
35-
// explicit port is specified.
34+
// discovered address. The target name is built using the discovered address
35+
// as the host and the DefaultGRPCPort constant for the port.
3636
NewTargets func(ctx context.Context, addr string) (targets []Target, err error)
3737

3838
// LookupHost is the function used to query the host.
@@ -174,6 +174,8 @@ func (d *DNSTargetDiscoverer) newTargets(ctx context.Context, addr string) ([]Ta
174174
}
175175

176176
return []Target{
177-
{Name: addr},
177+
{
178+
Name: net.JoinHostPort(addr, DefaultGRPCPort),
179+
},
178180
}, nil
179181
}

dns_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"net"
7+
"strings"
78
"time"
89

910
. "github.com/dogmatiq/discoverkit"
@@ -58,8 +59,8 @@ var _ = Describe("type DNSTargetDiscoverer", func() {
5859

5960
Expect(err).To(Equal(context.Canceled))
6061
Expect(targets).To(ConsistOf(
61-
Target{Name: "<addr-1>"},
62-
Target{Name: "<addr-2>"},
62+
Target{Name: "<addr-1>:50555"},
63+
Target{Name: "<addr-2>:50555"},
6364
))
6465
})
6566

@@ -84,7 +85,7 @@ var _ = Describe("type DNSTargetDiscoverer", func() {
8485
targetCtx context.Context,
8586
t Target,
8687
) {
87-
if t.Name == "<addr-1>" {
88+
if strings.Contains(t.Name, "<addr-1>") {
8889
go func() {
8990
<-targetCtx.Done()
9091
close(done)
@@ -151,8 +152,8 @@ var _ = Describe("type DNSTargetDiscoverer", func() {
151152
cancel()
152153
Expect(t.Name).To(
153154
Or(
154-
Equal("127.0.0.1"),
155-
Equal("::1"),
155+
Equal("127.0.0.1:50555"),
156+
Equal("[::1]:50555"),
156157
),
157158
)
158159
},

server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import (
77
"github.com/dogmatiq/interopspec/discoverspec"
88
)
99

10+
const (
11+
// DefaultGRPCPort is the default TCP port used by servers that implement
12+
// the APIs in interopspec, in particular the DiscoverAPI.
13+
DefaultGRPCPort = "50555"
14+
)
15+
1016
// Server is an implementation of discoverspec.DiscoverAPIServer.
1117
type Server struct {
1218
m sync.Mutex

0 commit comments

Comments
 (0)