Documentation ¶
Index ¶
- Variables
- func GetDefaultScheme() string
- func NewRoundRobinPicker(next int) *rrPicker
- func Register(driver Builder)
- func ResolveDone(ctx context.Context, target string, doneInfo DoneInfo, ...) error
- func ResolveNow(ctx context.Context, target string, opts ...ResolveNowOption) error
- func Resolvers() []string
- func SetDefaultScheme(scheme string)
- type Address
- type Build
- type BuildOption
- type BuildOptionFunc
- type Builder
- type ClientConn
- type DoneInfo
- type EmptyBuildOption
- type EmptyPickOption
- type EmptyResolveAddrOption
- type EmptyResolveDoneOption
- type EmptyResolveNowOption
- type EmptyResolveOneAddrOption
- type Pick
- type PickOption
- type PickOptionFunc
- type Picker
- type PickerFunc
- type ResolveAddrOption
- type ResolveAddrOptionFunc
- type ResolveDoneOption
- type ResolveDoneOptionFunc
- type ResolveDoneResolver
- type ResolveNowOption
- type ResolveNowOptionFunc
- type ResolveOneAddrOption
- type ResolveOneAddrOptionFunc
- type Resolver
- type State
- type Target
Constants ¶
This section is empty.
Variables ¶
var ErrBadResolverState = errors.New("bad resolver state")
ErrBadResolverState may be returned by UpdateState to indicate a problem with the provided name resolver data.
var ( // ErrNoAddrAvailable indicates no Addr is available for pick(). ErrNoAddrAvailable = errors.New("no Addr is available") )
Functions ¶
func GetDefaultScheme ¶
func GetDefaultScheme() string
GetDefaultScheme gets the default scheme that will be used.
func NewRoundRobinPicker ¶
func NewRoundRobinPicker(next int) *rrPicker
func Register ¶
func Register(driver Builder)
Register makes a database driver available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.
func ResolveDone ¶ added in v1.2.55
func ResolveNow ¶
func ResolveNow(ctx context.Context, target string, opts ...ResolveNowOption) error
func Resolvers ¶
func Resolvers() []string
Resolvers returns a sorted list of the names of the registered resolvers.
func SetDefaultScheme ¶
func SetDefaultScheme(scheme string)
SetDefaultScheme sets the default scheme that will be used. The default default scheme is "passthrough".
NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. The scheme set last overrides previously set values.
Types ¶
type Address ¶
type Address struct { // Addr is the server address on which a connection will be established. Addr string // ResolveLoad is the load received from resolver. ResolveLoad any }
Address represents a server the client connects to.
func ResolveAddr ¶
func ResolveOneAddr ¶
type Build ¶
type Build struct {
ClientConn ClientConn
}
Build includes additional information for the builder to create the resolver.
func (*Build) ApplyOptions ¶
func (o *Build) ApplyOptions(options ...BuildOption) *Build
ApplyOptions call apply() for all options one by one
type BuildOption ¶
type BuildOption interface {
// contains filtered or unexported methods
}
A BuildOption sets options.
func BuildWithClientConn ¶
func BuildWithClientConn(cc ClientConn) BuildOption
BuildWithClientConn append cc to Build
func WithBuildClientConn ¶ added in v1.2.55
func WithBuildClientConn(v ClientConn) BuildOption
WithBuildClientConn sets ClientConn in Build.
type BuildOptionFunc ¶
type BuildOptionFunc func(*Build)
BuildOptionFunc wraps a function that modifies Build into an implementation of the BuildOption interface.
type Builder ¶
type Builder interface { // Build creates a new resolver for the given target. // // gRPC dial calls Build synchronously, and fails if the returned error is // not nil. Build(ctx context.Context, target Target, opts ...BuildOption) (Resolver, error) // Scheme returns the scheme supported by this resolver. // Scheme is defined at https://github.com/grpc/grpc/blob/master/doc/naming.md. Scheme() string }
Builder is the interface that must be implemented by a database driver.
Database drivers may implement DriverContext for access to contexts and to parse the name only once for a pool of connections, instead of once per connection.
func Get ¶
Get returns the resolver builder registered with the given scheme.
If no builder is register with the scheme, nil will be returned.
func GetBuilderOrDefault ¶
type ClientConn ¶
type ClientConn interface { // UpdateState updates the state of the ClientConn appropriately. UpdateState(State) error // ReportError notifies the ClientConn that the Resolver encountered an // error. The ClientConn will notify the load balancer and begin calling // ResolveNow on the Resolver with exponential backoff. ReportError(error) }
ClientConn contains the callbacks for resolver to notify any updates to the gRPC ClientConn.
This interface is to be implemented by gRPC. Users should not need a brand new implementation of this interface. For the situations like testing, the new implementation should embed this interface. This allows gRPC to add new methods to this interface.
type DoneInfo ¶ added in v1.2.55
type DoneInfo struct { // Err is the rpc error the RPC finished with. It could be nil. // usually io.EOF represents server addr is resolved but unacceptable. Err error // Addr represents a server the client connects to. Addr Address Duration time.Duration }
DoneInfo contains additional information for done.
type EmptyBuildOption ¶
type EmptyBuildOption struct{}
EmptyBuildOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EmptyPickOption ¶
type EmptyPickOption struct{}
EmptyPickOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EmptyResolveAddrOption ¶
type EmptyResolveAddrOption struct{}
EmptyResolveAddrOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EmptyResolveDoneOption ¶ added in v1.2.55
type EmptyResolveDoneOption struct{}
EmptyResolveDoneOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EmptyResolveNowOption ¶
type EmptyResolveNowOption struct{}
EmptyResolveNowOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EmptyResolveOneAddrOption ¶
type EmptyResolveOneAddrOption struct{}
EmptyResolveOneAddrOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type Pick ¶
type Pick struct{}
Pick includes additional information for Pick.
func (*Pick) ApplyOptions ¶
func (o *Pick) ApplyOptions(options ...PickOption) *Pick
type PickOption ¶
type PickOption interface {
// contains filtered or unexported methods
}
A PickOption sets options.
type PickOptionFunc ¶
type PickOptionFunc func(*Pick)
PickOptionFunc wraps a function that modifies Pick into an implementation of the PickOption interface.
type Picker ¶
type Picker interface {
Pick(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)
}
Picker is used to pick an Address.
func NewErrPicker ¶
NewErrPicker returns a Picker that always returns err on Pick().
type PickerFunc ¶
The PickerFunc type is an adapter to allow the use of ordinary functions as Picker handlers. If f is a function with the appropriate signature, PickerFunc(f) is a Handler that calls f.
func (PickerFunc) Pick ¶
func (f PickerFunc) Pick(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)
Pick calls f(ctx, addrs, opts...).
type ResolveAddrOption ¶
type ResolveAddrOption interface {
// contains filtered or unexported methods
}
A ResolveAddrOption sets options.
type ResolveAddrOptionFunc ¶
type ResolveAddrOptionFunc func(*resolveAddr)
ResolveAddrOptionFunc wraps a function that modifies resolveAddr into an implementation of the ResolveAddrOption interface.
type ResolveDoneOption ¶ added in v1.2.55
type ResolveDoneOption interface {
// contains filtered or unexported methods
}
A ResolveDoneOption sets options.
type ResolveDoneOptionFunc ¶ added in v1.2.55
type ResolveDoneOptionFunc func(*resolveDone)
ResolveDoneOptionFunc wraps a function that modifies resolveDone into an implementation of the ResolveDoneOption interface.
type ResolveDoneResolver ¶ added in v1.2.55
type ResolveDoneResolver interface { Resolver // ResolveDone will be called after the RPC finished. // resolver can ignore this if it's not necessary. ResolveDone(ctx context.Context, doneInfo DoneInfo, opts ...ResolveDoneOption) }
ResolveDoneResolver extends Resolver with ResolveDone
type ResolveNowOption ¶
type ResolveNowOption interface {
// contains filtered or unexported methods
}
A ResolveNowOption sets options.
type ResolveNowOptionFunc ¶
type ResolveNowOptionFunc func(*resolveNow)
ResolveNowOptionFunc wraps a function that modifies resolveNow into an implementation of the ResolveNowOption interface.
type ResolveOneAddrOption ¶
type ResolveOneAddrOption interface {
// contains filtered or unexported methods
}
A ResolveOneAddrOption sets options.
func ResolveOneAddrOptionWithPickerOption ¶
func ResolveOneAddrOptionWithPickerOption(opts ...PickOption) ResolveOneAddrOption
ResolveOneAddrOptionWithPickerOption append PickOption to picker
func WithresolveOneAddrPicker ¶ added in v1.2.55
func WithresolveOneAddrPicker(v ...PickOption) ResolveOneAddrOption
WithresolveOneAddrPicker appends Picker in resolveOneAddr.
func WithresolveOneAddrPickerReplace ¶ added in v1.2.55
func WithresolveOneAddrPickerReplace(v ...PickOption) ResolveOneAddrOption
WithresolveOneAddrPickerReplace sets Picker in resolveOneAddr.
type ResolveOneAddrOptionFunc ¶
type ResolveOneAddrOptionFunc func(*resolveOneAddr)
ResolveOneAddrOptionFunc wraps a function that modifies resolveOneAddr into an implementation of the ResolveOneAddrOption interface.
type Resolver ¶
type Resolver interface { // ResolveOneAddr will be called to try to resolve the target name directly. // resolver can not ignore this if it's not necessary. // ResolveOneAddr may trigger and wait for ResolveNow if no addr in resolver cache ResolveOneAddr(ctx context.Context, opts ...ResolveOneAddrOption) (Address, error) // ResolveAddr will be called to try to resolve the target name directly. // resolver can not ignore this if it's not necessary. // ResolveAddr may trigger and wait for ResolveNow if no addr in resolver cache ResolveAddr(ctx context.Context, opts ...ResolveAddrOption) ([]Address, error) // ResolveNow will be called to try to resolve the target name // again. It's just a hint, resolver can ignore this if it's not necessary. // // It could be called multiple times concurrently. // It may trigger ClientConn to UpdateState or ReportError if failed. // It may update cache used by ResolveOneAddr or ResolveAddr. ResolveNow(ctx context.Context, opts ...ResolveNowOption) // Close closes the resolver. Close() }
Resolver watches for the updates on the specified target. Updates include address updates and service config updates.
func NewResolver ¶
type State ¶
type State struct { // Addresses is the latest set of resolved addresses for the target. Addresses []Address }
State contains the current Resolver state relevant to the ClientConn.
type Target ¶
type Target struct { // Deprecated: use URL.Scheme instead. Scheme string // Deprecated: use URL.Host instead. Authority string // Deprecated: use URL.Path or URL.Opaque instead. The latter is set when // the former is empty. Endpoint string // URL contains the parsed dial target with an optional default scheme added // to it if the original dial target contained no scheme or contained an // unregistered scheme. Any query params specified in the original dial // target can be accessed from here. URL url.URL }
func ParseTarget ¶
ParseTarget uses RFC 3986 semantics to parse the given target into a resolver.Target struct containing scheme, authority and endpoint. Query params are stripped from the endpoint.
If target is not a valid scheme://authority/endpoint as specified in https://github.com/grpc/grpc/blob/master/doc/naming.md, it returns {Endpoint: target}. Code borrowed from https://github.com/grpc/grpc-go/blob/v1.48.0/clientconn.go#L1619 See https://github.com/grpc/grpc-go/pull/4817
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package unix implements a resolver for unix targets.
|
Package unix implements a resolver for unix targets. |