fsdialer

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DialContext = func(ctx context.Context, network string, address string) (net.Conn, error) {
	return Default.DialContext(ctx, network, address)
}

DialContext dial default

Functions

func ContextWithInterceptor

func ContextWithInterceptor(ctx context.Context, its ...*Interceptor) context.Context

ContextWithInterceptor set dialer Interceptor to context these interceptors will exec before Simple.Interceptors

func MustRegisterInterceptor

func MustRegisterInterceptor(its ...*Interceptor)

MustRegisterInterceptor 给 Default 注册 Interceptor 若不支持将 panic

func TryRegisterInterceptor

func TryRegisterInterceptor(its ...*Interceptor) bool

TryRegisterInterceptor 尝试给 Default 注册 Interceptor 若注册失败将返回 false

Types

type CanInterceptor

type CanInterceptor interface {
	RegisterInterceptor(its ...*Interceptor)
}

CanInterceptor dialer can RegisterInterceptor

type ConnStatTracer

type ConnStatTracer struct {
	// contains filtered or unexported fields
}

ConnStatTracer 用于获取网络状态的拦截器

func (*ConnStatTracer) ConnInterceptor

func (ch *ConnStatTracer) ConnInterceptor() *fsconn.Interceptor

ConnInterceptor 获取 net.Conn 的状态拦截器

func (*ConnStatTracer) DialCost

func (ch *ConnStatTracer) DialCost() time.Duration

DialCost 获取累积的 Dial 耗时

func (*ConnStatTracer) DialFailTimes

func (ch *ConnStatTracer) DialFailTimes() int64

DialFailTimes 获取累积的 Dial 失败次数

func (*ConnStatTracer) DialTimes

func (ch *ConnStatTracer) DialTimes() int64

DialTimes 获取累积的 Dial 总次数

func (*ConnStatTracer) DialerInterceptor

func (ch *ConnStatTracer) DialerInterceptor() *Interceptor

DialerInterceptor 获取拨号器的拦截器,之后可将其注册到 Dialer

func (*ConnStatTracer) ReadCost

func (ch *ConnStatTracer) ReadCost() time.Duration

ReadCost 获取累积的读耗时

func (*ConnStatTracer) ReadSize

func (ch *ConnStatTracer) ReadSize() int64

ReadSize 获取累计读到的的字节大小

func (*ConnStatTracer) Reset

func (ch *ConnStatTracer) Reset()

Reset 将所有状态数据重置为 0

func (*ConnStatTracer) WriteCost

func (ch *ConnStatTracer) WriteCost() time.Duration

WriteCost 获取累积的写耗时

func (*ConnStatTracer) WriteSize

func (ch *ConnStatTracer) WriteSize() int64

WriteSize 获取累计写出的的字节大小

type DialContextFunc

type DialContextFunc func(ctx context.Context, network string, address string) (net.Conn, error)

DialContextFunc Dial func type

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network string, address string) (net.Conn, error)
}

Dialer dial connWithIt type

var Default Dialer = &Simple{}

Default default dialer

type Interceptor

type Interceptor struct {
	DialContext func(ctx context.Context, network string, address string, invoker DialContextFunc) (net.Conn, error)

	BeforeDialContext func(ctx context.Context, net string, addr string) (c context.Context, n string, a string)

	AfterDialContext func(ctx context.Context, net string, addr string, conn net.Conn, err error) (net.Conn, error)
}

Interceptor dialer interceptor

func InterceptorsFromContext

func InterceptorsFromContext(ctx context.Context) []*Interceptor

InterceptorsFromContext get DialerInterceptors from contexts

func TransConnInterceptor

func TransConnInterceptor(its ...*fsconn.Interceptor) *Interceptor

TransConnInterceptor 创建一个支持添加 Interceptor 的 Interceptor 当想给 Default 注册 全局的 Interceptor 的时候,可以使用该方法

type Simple

type Simple struct {
	// Invoker 可选,底层拨号器
	Invoker Dialer

	// Resolver 可选,dns 解析
	Resolver fsresolver.Resolver

	// Interceptors 可选,拦截器列表
	Interceptors []*Interceptor

	// Timeout 可选,超时时间
	Timeout time.Duration
}

Simple dialer

func (*Simple) DialContext

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

DialContext dial with Context

func (*Simple) RegisterInterceptor

func (d *Simple) RegisterInterceptor(its ...*Interceptor)

RegisterInterceptor register Interceptor

Jump to

Keyboard shortcuts

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