You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
kratos/transport/grpc/resolver/direct/builder.go

38 lines
848 B

package direct
import (
"strings"
"google.golang.org/grpc/resolver"
)
func init() {
resolver.Register(NewBuilder())
}
type directBuilder struct{}
// NewBuilder creates a directBuilder which is used to factory direct resolvers.
// example:
// direct://<authority>/127.0.0.1:9000,127.0.0.2:9000
func NewBuilder() resolver.Builder {
return &directBuilder{}
}
func (d *directBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
var addrs []resolver.Address
for _, addr := range strings.Split(target.Endpoint, ",") {
addrs = append(addrs, resolver.Address{Addr: addr})
}
err := cc.UpdateState(resolver.State{
Addresses: addrs,
})
if err != nil {
return nil, err
}
return newDirectResolver(), nil
}
func (d *directBuilder) Scheme() string {
return "direct"
}