dialer

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dialer provides a context-bound service which wraps a net.Dialer and the flags that configure it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LookupContextKey

func LookupContextKey(target any) (contextKey any, ok bool)

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

func SourceAnnotation() (string, string)

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

type Action = cli.Action

Action provides a context action that affects the dialer

func ContextKeyAnnotation

func ContextKeyAnnotation(contextKey any) Action

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

func ContextValue(d *Dialer) Action

ContextValue provides an action that registers the dialer in the context using its context key.

func FlagsAndArgs

func FlagsAndArgs(contextKey ...any) Action

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

func IDAnnotation(id ID) Action

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 SetBindAddress(v ...string) Action

func SetDialKeepAlive

func SetDialKeepAlive(v ...time.Duration) Action

func SetDialTimeout

func SetDialTimeout(s ...time.Duration) Action

func SetDisableDialKeepAlive

func SetDisableDialKeepAlive() Action

func SetInterface

func SetInterface(v ...string) Action

type Dialer

type Dialer struct {
	*net.Dialer
	cli.Action
	// contains filtered or unexported fields
}

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

func FromContext(ctx context.Context) *Dialer

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

func FromContextKey(ctx context.Context, contextKey any) *Dialer

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

func New(opts ...Option) *Dialer

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

func (d *Dialer) Apply(opts ...Option) error

Apply applies the given options to the dialer. Options must be applied before the first connection is dialed.

func (*Dialer) ContextKey

func (d *Dialer) ContextKey() any

ContextKey gets the key used to store the dialer in the context.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial connects to the address on the named network. See net.Dialer.Dial.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

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

func (d *Dialer) NewResolver(ctx context.Context) (*net.Resolver, error)

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.

func (*Dialer) Pipeline

func (d *Dialer) Pipeline() cli.Action

Pipeline obtains the action that the dialer contributes to the app

type ID

type ID int

ID identifies each of the flags and args registered by FlagsAndArgs

const (
	IDDialTimeout ID = iota
	IDDialKeepAlive
	IDDisableDialKeepAlive
	IDBindAddress
	IDInterface
	IDListInterfaces
)

func LookupID

func LookupID(target any) (ID, bool)

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) String

func (i ID) String() string

func (*ID) UnmarshalText

func (i *ID) UnmarshalText(text []byte) error

UnmarshalText parses the string representation of the Id, as produced by String, back into an Id.

type Option

type Option func(*Dialer) error

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 WithAction

func WithAction(a cli.Action) Option

WithAction sets the action

func WithBindAddress

func WithBindAddress(v string) Option

WithBindAddress binds connections to the given address on the local machine

func WithContextKey

func WithContextKey(contextKey any) Option

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

func WithDialKeepAlive(v time.Duration) Option

WithDialKeepAlive sets the interval between keep-alive probes for an active network connection

func WithDialTimeout

func WithDialTimeout(v time.Duration) Option

WithDialTimeout sets the maximum amount of time a dial waits for a connect to complete

func WithDisableDialKeepAlive

func WithDisableDialKeepAlive(v bool) Option

WithDisableDialKeepAlive disables dialer keep-alive probes

func WithInterface

func WithInterface(v string) Option

WithInterface uses the network interface, named by name or address, to connect

func WithResolver

func WithResolver(r *net.Resolver) Option

WithResolver sets the resolver to use directly, bypassing the default factory. Resolver middleware is still applied to it.

func WithResolverFactory

func WithResolverFactory(fn func(context.Context) (*net.Resolver, error)) Option

WithResolverFactory provides a factory for obtaining the resolver.

func WithResolverMiddleware

func WithResolverMiddleware(fns ...ResolverMiddleware) Option

WithResolverMiddleware adds middleware for the resolver

func (Option) Execute

func (o Option) Execute(ctx context.Context) error

Execute applies the option to the dialer found in the context.

type ResolverMiddleware

type ResolverMiddleware func(context.Context, *net.Resolver) *net.Resolver

ResolverMiddleware provides middleware to the resolver

Jump to

Keyboard shortcuts

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