directbuilder.go 654 B

1234567891011121314151617181920212223242526272829303132
  1. package resolver
  2. import (
  3. "strings"
  4. "google.golang.org/grpc/resolver"
  5. )
  6. type directBuilder struct{}
  7. func (d *directBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (
  8. resolver.Resolver, error) {
  9. var addrs []resolver.Address
  10. endpoints := strings.FieldsFunc(target.Endpoint, func(r rune) bool {
  11. return r == EndpointSepChar
  12. })
  13. for _, val := range subset(endpoints, subsetSize) {
  14. addrs = append(addrs, resolver.Address{
  15. Addr: val,
  16. })
  17. }
  18. cc.UpdateState(resolver.State{
  19. Addresses: addrs,
  20. })
  21. return &nopResolver{cc: cc}, nil
  22. }
  23. func (d *directBuilder) Scheme() string {
  24. return DirectScheme
  25. }