mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-25 02:08:44 +08:00
20f665ede8
* implement k8s service discovery * simplify code * use default namespace if not provided * disable codecov bot comment * ignore adhoc dir * simplify building target in NewClient * reformat code * Fix filepath (#990) * format code, and reorg imports (#991) * add more unit test Co-authored-by: anqiansong <anqiansong@gmail.com>
35 lines
699 B
Go
35 lines
699 B
Go
package resolver
|
|
|
|
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
|
|
endpoints := strings.FieldsFunc(target.Endpoint, 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
|
|
}
|