github.com/kaydxh/golang@v0.0.131/go/net/resolver/build.go (about) 1 /* 2 *Copyright (c) 2022, kaydxh 3 * 4 *Permission is hereby granted, free of charge, to any person obtaining a copy 5 *of this software and associated documentation files (the "Software"), to deal 6 *in the Software without restriction, including without limitation the rights 7 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 *copies of the Software, and to permit persons to whom the Software is 9 *furnished to do so, subject to the following conditions: 10 * 11 *The above copyright notice and this permission notice shall be included in all 12 *copies or substantial portions of the Software. 13 * 14 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 *SOFTWARE. 21 */ 22 package resolver 23 24 import ( 25 "context" 26 "net" 27 ) 28 29 // Address represents a server the client connects to. 30 // 31 // Experimental 32 // 33 // Notice: This type is EXPERIMENTAL and may be changed or removed in a 34 // later release. 35 type Address struct { 36 // Addr is the server address on which a connection will be established. 37 Addr string 38 39 // ServerName is the name of this address. 40 // If non-empty, the ServerName is used as the transport certification authority for 41 // the address, instead of the hostname from the Dial target string. In most cases, 42 // this should not be set. 43 // 44 // If Type is GRPCLB, ServerName should be the name of the remote load 45 // balancer, not the name of the backend. 46 // 47 // WARNING: ServerName must only be populated with trusted values. It 48 // is insecure to populate it with data from untrusted inputs since untrusted 49 // values could be used to bypass the authority checks performed by TLS. 50 ServerName string 51 } 52 53 // State contains the current Resolver state relevant to the ClientConn. 54 type State struct { 55 // Addresses is the latest set of resolved addresses for the target. 56 Addresses []Address 57 } 58 59 // ClientConn contains the callbacks for resolver to notify any updates 60 // to the gRPC ClientConn. 61 // 62 // This interface is to be implemented by gRPC. Users should not need a 63 // brand new implementation of this interface. For the situations like 64 // testing, the new implementation should embed this interface. This allows 65 // gRPC to add new methods to this interface. 66 type ClientConn interface { 67 // UpdateState updates the state of the ClientConn appropriately. 68 UpdateState(State) error 69 // ReportError notifies the ClientConn that the Resolver encountered an 70 // error. The ClientConn will notify the load balancer and begin calling 71 // ResolveNow on the Resolver with exponential backoff. 72 ReportError(error) 73 } 74 75 type ResolverBuildOptions struct { 76 // if cc is not nil, will update client connection state when resolved 77 Cc ClientConn 78 // Dialer is the custom dialer used by the ClientConn for dialling the 79 // target gRPC service (set via WithDialer). In cases where a name 80 // resolution service requires the same dialer, the resolver may use this 81 // field. In most cases though, it is not appropriate, and this field may 82 // be ignored. 83 Dialer func(context.Context, string) (net.Conn, error) 84 } 85 86 /* 87 type ResolverBuild struct { 88 Opts ResolverBuildOptions 89 } 90 91 func NewResolverBuild() { 92 } 93 */ 94 95 // Builder creates a resolver that will be used to watch name resolution updates. 96 type Builder interface { 97 // Build creates a new resolver for the given target 98 // 99 // gRPC dial calls Build synchronously, and fails if the returned error is 100 // not nil. 101 // Note: only call once for one schema, or will memory leak 102 Build(target Target, opts ...ResolverBuildOption) (Resolver, error) 103 // Scheme returns the scheme supported by this resolver. 104 // Scheme is defined at https://github.com/grpc/grpc/blob/master/doc/naming.md. 105 Scheme() string 106 }