You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
699 B
Go
35 lines
699 B
Go
3 years ago
|
package internal
|
||
4 years ago
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"google.golang.org/grpc/resolver"
|
||
|
)
|
||
|
|
||
|
type directBuilder struct{}
|
||
|
|
||
|
func (d *directBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (
|
||
|
resolver.Resolver, error) {
|
||
|
var addrs []resolver.Address
|
||
4 years ago
|
endpoints := strings.FieldsFunc(target.Endpoint, func(r rune) bool {
|
||
4 years ago
|
return r == EndpointSepChar
|
||
4 years ago
|
})
|
||
4 years ago
|
|
||
|
for _, val := range subset(endpoints, subsetSize) {
|
||
|
addrs = append(addrs, resolver.Address{
|
||
|
Addr: val,
|
||
|
})
|
||
|
}
|
||
3 years ago
|
if err := cc.UpdateState(resolver.State{
|
||
4 years ago
|
Addresses: addrs,
|
||
3 years ago
|
}); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
4 years ago
|
|
||
|
return &nopResolver{cc: cc}, nil
|
||
|
}
|
||
|
|
||
|
func (d *directBuilder) Scheme() string {
|
||
|
return DirectScheme
|
||
|
}
|