Documentation ¶
Index ¶
- Variables
- func ContextWithInterceptor(ctx context.Context, its ...*Interceptor) context.Context
- func MustRegisterInterceptor(its ...*Interceptor)
- func TryRegisterInterceptor(its ...*Interceptor) bool
- type CacheInterceptor
- type Cached
- func (r *Cached) ExpirationFromEnv() time.Duration
- func (r *Cached) GetInterceptors() []*Interceptor
- func (r *Cached) LookupIP(ctx context.Context, network, host string) (ips []net.IP, err error)
- func (r *Cached) LookupIPAddr(ctx context.Context, host string) (ips []net.IPAddr, err error)
- func (r *Cached) RegisterInterceptor(its ...*Interceptor)
- type CanIntercept
- type Interceptor
- type LookupIPAddrFunc
- type LookupIPFunc
- type LookupIPer
- type LookupIPerGroup
- type Resolver
Constants ¶
This section is empty.
Variables ¶
var LookupIP = func(ctx context.Context, network, host string) ([]net.IP, error) { return Default.LookupIP(ctx, network, host) }
LookupIP Default.LookupIP
var LookupIPAddr = func(ctx context.Context, host string) ([]net.IPAddr, error) { return Default.LookupIPAddr(ctx, host) }
LookupIPAddr Default.LookupIPAddr
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 ¶
ExpirationFromEnv parser Expiration from os.env
func (*Cached) GetInterceptors ¶
func (r *Cached) GetInterceptors() []*Interceptor
GetInterceptors read Interceptor list
func (*Cached) LookupIPAddr ¶
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 ¶
LookupIPAddrFunc LookupIPAddr func type
type LookupIPFunc ¶
LookupIPFunc lookupIP func type
type LookupIPer ¶
LookupIPer has LookupIP func