passthrough.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. *
  3. * Copyright 2017 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. // Package passthrough implements a pass-through resolver. It sends the target
  19. // name without scheme back to gRPC as resolved address.
  20. package passthrough
  21. import "google.golang.org/grpc/resolver"
  22. const scheme = "passthrough"
  23. type passthroughBuilder struct{}
  24. func (*passthroughBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOption) (resolver.Resolver, error) {
  25. r := &passthroughResolver{
  26. target: target,
  27. cc: cc,
  28. }
  29. r.start()
  30. return r, nil
  31. }
  32. func (*passthroughBuilder) Scheme() string {
  33. return scheme
  34. }
  35. type passthroughResolver struct {
  36. target resolver.Target
  37. cc resolver.ClientConn
  38. }
  39. func (r *passthroughResolver) start() {
  40. r.cc.NewAddress([]resolver.Address{{Addr: r.target.Endpoint}})
  41. }
  42. func (*passthroughResolver) ResolveNow(o resolver.ResolveNowOption) {}
  43. func (*passthroughResolver) Close() {}
  44. func init() {
  45. resolver.Register(&passthroughBuilder{})
  46. }