-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstaticbuilder.go
45 lines (34 loc) · 1.1 KB
/
staticbuilder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gubernator
import (
"strings"
"google.golang.org/grpc/resolver"
)
type staticBuilder struct{}
var _ resolver.Builder = (*staticBuilder)(nil)
func (sb *staticBuilder) Scheme() string {
return "static"
}
func (sb *staticBuilder) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (resolver.Resolver, error) {
var resolverAddrs []resolver.Address
for _, address := range strings.Split(target.Endpoint(), ",") {
resolverAddrs = append(resolverAddrs, resolver.Address{
Addr: address,
ServerName: address,
})
}
if err := cc.UpdateState(resolver.State{Addresses: resolverAddrs}); err != nil {
return nil, err
}
return &staticResolver{cc: cc}, nil
}
// NewStaticBuilder returns a builder which returns a staticResolver that tells GRPC
// to connect a specific peer in the cluster.
func NewStaticBuilder() resolver.Builder {
return &staticBuilder{}
}
type staticResolver struct {
cc resolver.ClientConn
}
func (sr *staticResolver) ResolveNow(_ resolver.ResolveNowOptions) {}
func (sr *staticResolver) Close() {}
var _ resolver.Resolver = (*staticResolver)(nil)