Documentation
¶
Overview ¶
Package dialer provides a context-bound service which wraps a net.Dialer and the flags that configure it.
Index ¶
- func LookupContextKey(target any) (contextKey any, ok bool)
- func SourceAnnotation() (string, string)
- type Action
- func ContextKeyAnnotation(contextKey any) Action
- func ContextValue(d *Dialer) Action
- func FlagsAndArgs(contextKey ...any) Action
- func IDAnnotation(id ID) Action
- func ListInterfaces() Action
- func SetBindAddress(v ...string) Action
- func SetDialKeepAlive(v ...time.Duration) Action
- func SetDialTimeout(s ...time.Duration) Action
- func SetDisableDialKeepAlive() Action
- func SetInterface(v ...string) Action
- type Dialer
- func (d *Dialer) Apply(opts ...Option) error
- func (d *Dialer) ContextKey() any
- func (d *Dialer) Dial(network, address string) (net.Conn, error)
- func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func (d *Dialer) NewResolver(ctx context.Context) (*net.Resolver, error)
- func (d *Dialer) Pipeline() cli.Action
- type ID
- type Option
- func WithAction(a cli.Action) Option
- func WithBindAddress(v string) Option
- func WithContextKey(contextKey any) Option
- func WithDefaultAction() Option
- func WithDefaultResolverFactory() Option
- func WithDialKeepAlive(v time.Duration) Option
- func WithDialTimeout(v time.Duration) Option
- func WithDisableDialKeepAlive(v bool) Option
- func WithInterface(v string) Option
- func WithResolver(r *net.Resolver) Option
- func WithResolverFactory(fn func(context.Context) (*net.Resolver, error)) Option
- func WithResolverMiddleware(fns ...ResolverMiddleware) Option
- type ResolverMiddleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LookupContextKey ¶
LookupContextKey gets the context key which the flag, arg, or command was annotated with by ContextKeyAnnotation, if present. target can be any value which exposes annotation data, such as *cli.Flag, *cli.Arg, or *cli.Context.
func SourceAnnotation ¶
SourceAnnotation gets the name and value of the annotation added to the Data of all flags that are initialized from this package
Types ¶
type Action ¶
Action provides a context action that affects the dialer
func ContextKeyAnnotation ¶
ContextKeyAnnotation provides an action which annotates a flag, arg, or command with the context key of the dialer that it configures. The SetX actions and the Option actions resolve the dialer using this key rather than the default context key. The annotation is found from the flag or arg itself or from any of its enclosing commands.
func ContextValue ¶
ContextValue provides an action that registers the dialer in the context using its context key.
func FlagsAndArgs ¶
FlagsAndArgs provides the flags and args for configuring the dialer. By default, these configure the dialer registered under the default context key. To configure a dialer registered with WithContextKey, specify the context key; the flags are then annotated with ContextKeyAnnotation. At most one context key can be specified.
func IDAnnotation ¶
IDAnnotation provides an action which annotates the identity of a flag or arg registered by FlagsAndArgs. It is applied directly to the flag or arg at its point of registration, rather than from within the Uses pipeline or binding delegate of the corresponding SetX function.
func ListInterfaces ¶
func ListInterfaces() Action
func SetBindAddress ¶
func SetDialKeepAlive ¶
func SetDialTimeout ¶
func SetDisableDialKeepAlive ¶
func SetDisableDialKeepAlive() Action
func SetInterface ¶
type Dialer ¶
Dialer represents a net.Dialer plus a default action. Dialer is created with New, and its settings are configured either with options or by the flags which the default action registers.
func FromContext ¶
FromContext obtains the dialer from the context. When the context is a *cli.Context, the ContextKeyAnnotation of the flag, arg, or command being executed can be used to determine which dialer is used; otherwise, or if the annotation is not present, the default context key is used to resolve the dialer.
func FromContextKey ¶
FromContextKey obtains the dialer from the context using the given context key, which is the one specified with WithContextKey. If no dialer is present, nil is returned.
func New ¶
New creates a new dialer. By default, it is also initialized with a default action that registers the dialer in the context and registers useful flags.
func (*Dialer) Apply ¶
Apply applies the given options to the dialer. Options must be applied before the first connection is dialed.
func (*Dialer) ContextKey ¶
ContextKey gets the key used to store the dialer in the context.
func (*Dialer) DialContext ¶
DialContext connects to the address on the named network using the context. It first obtains the resolver if that hasn't already happened. See net.Dialer.DialContext.
func (*Dialer) NewResolver ¶
NewResolver creates (or returns the cached) resolver for the dialer. It is created the first time that it is needed, which is either from Dial, DialContext, or calling this method.
type ID ¶
type ID int
ID identifies each of the flags and args registered by FlagsAndArgs
func LookupID ¶
LookupID gets the identity of a flag or arg registered by FlagsAndArgs, if present. target can be any value which exposes annotation data, such as *cli.Flag, *cli.Arg, or *cli.Context.
func (*ID) UnmarshalText ¶
UnmarshalText parses the string representation of the Id, as produced by String, back into an Id.
type Option ¶
Option provides an option to the dialer. Option can be used as an Action, typically within the Uses or Before pipeline, in which case it applies to the dialer found in the context.
func WithBindAddress ¶
WithBindAddress binds connections to the given address on the local machine
func WithContextKey ¶
WithContextKey sets the key under which the dialer is stored in the context. If this option is not specified, a default key is used.
func WithDefaultAction ¶
func WithDefaultAction() Option
WithDefaultAction sets the action to the default, which registers the dialer in the context along with the flags that configure it.
func WithDefaultResolverFactory ¶
func WithDefaultResolverFactory() Option
WithDefaultResolverFactory sets up the default resolver factory, which provides a resolver that uses the system defaults. This option is applied automatically by New.
func WithDialKeepAlive ¶
WithDialKeepAlive sets the interval between keep-alive probes for an active network connection
func WithDialTimeout ¶
WithDialTimeout sets the maximum amount of time a dial waits for a connect to complete
func WithDisableDialKeepAlive ¶
WithDisableDialKeepAlive disables dialer keep-alive probes
func WithInterface ¶
WithInterface uses the network interface, named by name or address, to connect
func WithResolver ¶
WithResolver sets the resolver to use directly, bypassing the default factory. Resolver middleware is still applied to it.
func WithResolverFactory ¶
WithResolverFactory provides a factory for obtaining the resolver.
func WithResolverMiddleware ¶
func WithResolverMiddleware(fns ...ResolverMiddleware) Option
WithResolverMiddleware adds middleware for the resolver