mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 09:40:24 +08:00
f7a60cdc24
* fix: remove deprecated dependencies * backup * fix test error
36 lines
772 B
Go
36 lines
772 B
Go
package internal
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/zrpc/resolver/internal/targets"
|
|
"google.golang.org/grpc/resolver"
|
|
)
|
|
|
|
type directBuilder struct{}
|
|
|
|
func (d *directBuilder) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (
|
|
resolver.Resolver, error) {
|
|
var addrs []resolver.Address
|
|
endpoints := strings.FieldsFunc(targets.GetEndpoints(target), func(r rune) bool {
|
|
return r == EndpointSepChar
|
|
})
|
|
|
|
for _, val := range subset(endpoints, subsetSize) {
|
|
addrs = append(addrs, resolver.Address{
|
|
Addr: val,
|
|
})
|
|
}
|
|
if err := cc.UpdateState(resolver.State{
|
|
Addresses: addrs,
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &nopResolver{cc: cc}, nil
|
|
}
|
|
|
|
func (d *directBuilder) Scheme() string {
|
|
return DirectScheme
|
|
}
|