resolver

package
v1.2.78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadResolverState = errors.New("bad resolver state")

ErrBadResolverState may be returned by UpdateState to indicate a problem with the provided name resolver data.

View Source
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 ResolveDone(ctx context.Context, target string, doneInfo DoneInfo, opts ...ResolveDoneOption) error

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 PickFirst

func PickFirst(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)

func ResolveAddr

func ResolveAddr(ctx context.Context, target string, opts ...ResolveAddrOption) ([]Address, error)

func ResolveOneAddr

func ResolveOneAddr(ctx context.Context, target string, opts ...ResolveOneAddrOption) (Address, error)

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

func Get(scheme string) Builder

Get returns the resolver builder registered with the given scheme.

If no builder is register with the scheme, nil will be returned.

func GetBuilderOrDefault

func GetBuilderOrDefault(target string) (Builder, error)

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

func NewErrPicker(err error) Picker

NewErrPicker returns a Picker that always returns err on Pick().

type PickerFunc

type PickerFunc func(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)

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

func NewResolver(ctx context.Context, target string, opts ...BuildOption) (Resolver, error)

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

func ParseTarget(target string) Target

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

Directories

Path Synopsis
Package unix implements a resolver for unix targets.
Package unix implements a resolver for unix targets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL