fsresolver

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: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LookupIP = func(ctx context.Context, network, host string) ([]net.IP, error) {
	return Default.LookupIP(ctx, network, host)
}

LookupIP Default.LookupIP

View Source
var LookupIPAddr = func(ctx context.Context, host string) ([]net.IPAddr, error) {
	return Default.LookupIPAddr(ctx, host)
}

LookupIPAddr Default.LookupIPAddr

View Source
var PrintResolverLog = &Interceptor{
	LookupIP: func(ctx context.Context, network, host string, invoker LookupIPFunc) ([]net.IP, error) {
		start := time.Now()
		ret, err := invoker(ctx, network, host)
		cost := time.Since(start)
		log.Printf("LookupIP(%q,%q)=(%v,%v) cost=%s\n", network, host, ret, err, cost)
		return ret, err
	},
	LookupIPAddr: func(ctx context.Context, host string, invoker LookupIPAddrFunc) ([]net.IPAddr, error) {
		start := time.Now()
		ret, err := invoker(ctx, host)
		cost := time.Since(start)
		log.Printf("LookupIPAddr(%q)=(%v,%v) cost=%s\n", host, ret, err, cost)
		return ret, err
	},
}

PrintResolverLog print Resolver log interceptor

Functions

func ContextWithInterceptor

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

ContextWithInterceptor set Resolver Interceptor to context these interceptors will exec before Dialer.Interceptors

func MustRegisterInterceptor

func MustRegisterInterceptor(its ...*Interceptor)

MustRegisterInterceptor 给 DefaultDialer 注册 DialerInterceptor 若不支持将 panic

func TryRegisterInterceptor

func TryRegisterInterceptor(its ...*Interceptor) bool

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

Types

type CacheInterceptor

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

CacheInterceptor 总是缓存查询结果

func (*CacheInterceptor) Interceptor

func (ci *CacheInterceptor) Interceptor() *Interceptor

func (*CacheInterceptor) SetEnable

func (ci *CacheInterceptor) SetEnable(enable bool)

SetEnable 设置状态,默认是 enable 的

func (*CacheInterceptor) Stats

func (ci *CacheInterceptor) Stats() map[string]int64

type Cached

type Cached struct {
	Invoker Resolver

	// Interceptors 可选,拦截器,先注册的后执行
	Interceptors []*Interceptor

	// Expiration cache Expiration
	// <=0 means disabled
	Expiration time.Duration
	// contains filtered or unexported fields
}

Cached Resolver with Cache

func (*Cached) ExpirationFromEnv

func (r *Cached) ExpirationFromEnv() time.Duration

ExpirationFromEnv parser Expiration from os.env

func (*Cached) GetInterceptors

func (r *Cached) GetInterceptors() []*Interceptor

GetInterceptors read Interceptor list

func (*Cached) LookupIP

func (r *Cached) LookupIP(ctx context.Context, network, host string) (ips []net.IP, err error)

LookupIP Lookup IP

func (*Cached) LookupIPAddr

func (r *Cached) LookupIPAddr(ctx context.Context, host string) (ips []net.IPAddr, err error)

LookupIPAddr Lookup IPAddr

func (*Cached) RegisterInterceptor

func (r *Cached) RegisterInterceptor(its ...*Interceptor)

RegisterInterceptor Register Interceptor

type CanIntercept

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

CanIntercept 支持注册 Interceptor

type Interceptor

type Interceptor struct {
	LookupIP func(ctx context.Context, network, host string, invoker LookupIPFunc) ([]net.IP, error)

	BeforeLookupIP func(ctx context.Context, network, host string) (c context.Context, n, h string)
	AfterLookupIP  func(ctx context.Context, network, host string, ips []net.IP, err error) ([]net.IP, error)

	LookupIPAddr func(ctx context.Context, host string, invoker LookupIPAddrFunc) ([]net.IPAddr, error)

	BeforeLookupIPAddr func(ctx context.Context, host string) (ctxNew context.Context, hostNew string)
	AfterLookupIPAddr  func(ctx context.Context, host string, addrs []net.IPAddr, err error) ([]net.IPAddr, error)
}

Interceptor Resolver Interceptor

func ToInterceptor

func ToInterceptor(r Resolver) *Interceptor

ToInterceptor convert Resolver to Interceptor

type LookupIPAddrFunc

type LookupIPAddrFunc func(ctx context.Context, host string) ([]net.IPAddr, error)

LookupIPAddrFunc LookupIPAddr func type

type LookupIPFunc

type LookupIPFunc func(ctx context.Context, network, host string) ([]net.IP, error)

LookupIPFunc lookupIP func type

type LookupIPer

type LookupIPer interface {
	LookupIP(ctx context.Context, network, host string) ([]net.IP, error)
}

LookupIPer has LookupIP func

type LookupIPerGroup

type LookupIPerGroup []LookupIPer

LookupIPerGroup LookupIPer slice

func (LookupIPerGroup) LookupIP

func (hs LookupIPerGroup) LookupIP(ctx context.Context, network, host string) ([]net.IP, error)

LookupIP Lookup IP

type Resolver

type Resolver interface {
	LookupIP(ctx context.Context, network, host string) ([]net.IP, error)
	LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
}

Resolver resolver type

var Default Resolver = &Cached{
	Expiration: defaultResolverExpiration(),
}

Default default Resolver, result has 3 min cache

Environment Variables 'FSGO_RESOLVER_EXP' can set the default cache lifetime
eg: export FSGO_RESOLVER_EXP="10m" set cache lifetime as 10 minute

Jump to

Keyboard shortcuts

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