utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RecHandleKey 是否被递归处理
	RecHandleKey ctxKey = "TS_REC_HANDLE"
)

Variables

This section is empty.

Functions

func CtxDebug

func CtxDebug(ctx context.Context, format string, args ...interface{})

CtxDebug logger.Debugf的封装,logger从context中获取

func CtxError

func CtxError(ctx context.Context, format string, args ...interface{})

CtxError logger.Errorf的封装,logger从context中获取

func CtxInfo

func CtxInfo(ctx context.Context, format string, args ...interface{})

CtxInfo logger.Infof的封装,logger从context中获取

func CtxWarn

func CtxWarn(ctx context.Context, format string, args ...interface{})

CtxWarn logger.Warnf的封装,logger从context中获取

func FastestPingIP

func FastestPingIP(ipAddr []string, tcpPort int, timeout time.Duration,
) (string, int64, error)

FastestPingIP 向指定IP地址列表同时发起ping,返回ping值最低的IP地址和耗时

func FormatECS

func FormatECS(r *dns.Msg) string

FormatECS 将DNS请求/响应里的EDNS CLIENT SUBNET对象格式化为字符串

func NewCtx

func NewCtx(logger *logrus.Logger, logID uint16) context.Context

NewCtx 返回一个已放入logger的ctx,用来传递给CtxInfo

func ParseECS

func ParseECS(s string) (ecs *dns.EDNS0_SUBNET, err error)

ParseECS 将字符串(IP/CIDR)转换为EDNS CLIENT SUBNET对象

func PingIP

func PingIP(ipAddr string, tcpPort int, timeout time.Duration) error

PingIP 向指定ip地址发起icmp ping/tcp ping(如tcpPort大于0),返回值为nil代表ping成功

func RemoveA

func RemoveA(resp *dns.Msg)

RemoveA 移除dns响应中的A记录

func RemoveEDNSCookie

func RemoveEDNSCookie(msg *dns.Msg)

RemoveEDNSCookie 移除EDNS Cookie

func SetDefaultECS

func SetDefaultECS(r *dns.Msg, ecs *dns.EDNS0_SUBNET)

SetDefaultECS 为DNS请求/响应设置默认的ECS对象

func WithFields

func WithFields(ctx context.Context, fields logrus.Fields) context.Context

WithFields 在ctx内放入用于打印日志的fields,已有时会被覆盖

Types

type FakeRespWriter

type FakeRespWriter struct {
	Msg   *dns.Msg
	Bytes []byte
}

func NewFakeRespWriter

func NewFakeRespWriter() *FakeRespWriter

NewFakeRespWriter 创建一个FakeRespWriter,用于手动请求dns.Handler时获取DNS响应

func (*FakeRespWriter) Close

func (w *FakeRespWriter) Close() error

func (*FakeRespWriter) Hijack

func (w *FakeRespWriter) Hijack()

func (*FakeRespWriter) LocalAddr

func (w *FakeRespWriter) LocalAddr() net.Addr

func (*FakeRespWriter) RemoteAddr

func (w *FakeRespWriter) RemoteAddr() net.Addr

func (*FakeRespWriter) TsigStatus

func (w *FakeRespWriter) TsigStatus() error

func (*FakeRespWriter) TsigTimersOnly

func (w *FakeRespWriter) TsigTimersOnly(bool)

func (*FakeRespWriter) Write

func (w *FakeRespWriter) Write(bytes []byte) (int, error)

func (*FakeRespWriter) WriteMsg

func (w *FakeRespWriter) WriteMsg(msg *dns.Msg) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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