update registry

This commit is contained in:
ginuerzh
2022-02-27 22:32:15 +08:00
parent 0aee4f0ebd
commit 07132d8de7
115 changed files with 651 additions and 680 deletions

View File

@ -42,7 +42,7 @@ func createAdmission(ctx *gin.Context) {
v := parsing.ParseAdmission(&req.Data)
if err := registry.Admission().Register(req.Data.Name, v); err != nil {
if err := registry.AdmissionRegistry().Register(req.Data.Name, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -86,7 +86,7 @@ func updateAdmission(ctx *gin.Context) {
ctx.ShouldBindUri(&req)
ctx.ShouldBindJSON(&req.Data)
if !registry.Admission().IsRegistered(req.Admission) {
if !registry.AdmissionRegistry().IsRegistered(req.Admission) {
writeError(ctx, ErrNotFound)
return
}
@ -95,9 +95,9 @@ func updateAdmission(ctx *gin.Context) {
v := parsing.ParseAdmission(&req.Data)
registry.Admission().Unregister(req.Admission)
registry.AdmissionRegistry().Unregister(req.Admission)
if err := registry.Admission().Register(req.Admission, v); err != nil {
if err := registry.AdmissionRegistry().Register(req.Admission, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -143,11 +143,11 @@ func deleteAdmission(ctx *gin.Context) {
var req deleteAdmissionRequest
ctx.ShouldBindUri(&req)
if !registry.Admission().IsRegistered(req.Admission) {
if !registry.AdmissionRegistry().IsRegistered(req.Admission) {
writeError(ctx, ErrNotFound)
return
}
registry.Admission().Unregister(req.Admission)
registry.AdmissionRegistry().Unregister(req.Admission)
cfg := config.Global()
admissiones := cfg.Admissions

View File

@ -41,7 +41,7 @@ func createAuther(ctx *gin.Context) {
}
v := parsing.ParseAuther(&req.Data)
if err := registry.Auther().Register(req.Data.Name, v); err != nil {
if err := registry.AutherRegistry().Register(req.Data.Name, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -85,7 +85,7 @@ func updateAuther(ctx *gin.Context) {
ctx.ShouldBindUri(&req)
ctx.ShouldBindJSON(&req.Data)
if !registry.Auther().IsRegistered(req.Auther) {
if !registry.AutherRegistry().IsRegistered(req.Auther) {
writeError(ctx, ErrNotFound)
return
}
@ -93,9 +93,9 @@ func updateAuther(ctx *gin.Context) {
req.Data.Name = req.Auther
v := parsing.ParseAuther(&req.Data)
registry.Auther().Unregister(req.Auther)
registry.AutherRegistry().Unregister(req.Auther)
if err := registry.Auther().Register(req.Auther, v); err != nil {
if err := registry.AutherRegistry().Register(req.Auther, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -141,11 +141,11 @@ func deleteAuther(ctx *gin.Context) {
var req deleteAutherRequest
ctx.ShouldBindUri(&req)
if !registry.Auther().IsRegistered(req.Auther) {
if !registry.AutherRegistry().IsRegistered(req.Auther) {
writeError(ctx, ErrNotFound)
return
}
registry.Auther().Unregister(req.Auther)
registry.AutherRegistry().Unregister(req.Auther)
cfg := config.Global()
authers := cfg.Authers

View File

@ -42,7 +42,7 @@ func createBypass(ctx *gin.Context) {
v := parsing.ParseBypass(&req.Data)
if err := registry.Bypass().Register(req.Data.Name, v); err != nil {
if err := registry.BypassRegistry().Register(req.Data.Name, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -86,7 +86,7 @@ func updateBypass(ctx *gin.Context) {
ctx.ShouldBindUri(&req)
ctx.ShouldBindJSON(&req.Data)
if !registry.Bypass().IsRegistered(req.Bypass) {
if !registry.BypassRegistry().IsRegistered(req.Bypass) {
writeError(ctx, ErrNotFound)
return
}
@ -95,9 +95,9 @@ func updateBypass(ctx *gin.Context) {
v := parsing.ParseBypass(&req.Data)
registry.Bypass().Unregister(req.Bypass)
registry.BypassRegistry().Unregister(req.Bypass)
if err := registry.Bypass().Register(req.Bypass, v); err != nil {
if err := registry.BypassRegistry().Register(req.Bypass, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -143,11 +143,11 @@ func deleteBypass(ctx *gin.Context) {
var req deleteBypassRequest
ctx.ShouldBindUri(&req)
if !registry.Bypass().IsRegistered(req.Bypass) {
if !registry.BypassRegistry().IsRegistered(req.Bypass) {
writeError(ctx, ErrNotFound)
return
}
registry.Bypass().Unregister(req.Bypass)
registry.BypassRegistry().Unregister(req.Bypass)
cfg := config.Global()
bypasses := cfg.Bypasses

View File

@ -46,7 +46,7 @@ func createChain(ctx *gin.Context) {
return
}
if err := registry.Chain().Register(req.Data.Name, v); err != nil {
if err := registry.ChainRegistry().Register(req.Data.Name, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -91,7 +91,7 @@ func updateChain(ctx *gin.Context) {
ctx.ShouldBindUri(&req)
ctx.ShouldBindJSON(&req.Data)
if !registry.Chain().IsRegistered(req.Chain) {
if !registry.ChainRegistry().IsRegistered(req.Chain) {
writeError(ctx, ErrNotFound)
return
}
@ -104,9 +104,9 @@ func updateChain(ctx *gin.Context) {
return
}
registry.Chain().Unregister(req.Chain)
registry.ChainRegistry().Unregister(req.Chain)
if err := registry.Chain().Register(req.Chain, v); err != nil {
if err := registry.ChainRegistry().Register(req.Chain, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -152,11 +152,11 @@ func deleteChain(ctx *gin.Context) {
var req deleteChainRequest
ctx.ShouldBindUri(&req)
if !registry.Chain().IsRegistered(req.Chain) {
if !registry.ChainRegistry().IsRegistered(req.Chain) {
writeError(ctx, ErrNotFound)
return
}
registry.Chain().Unregister(req.Chain)
registry.ChainRegistry().Unregister(req.Chain)
cfg := config.Global()
chains := cfg.Chains

View File

@ -42,7 +42,7 @@ func createHosts(ctx *gin.Context) {
v := parsing.ParseHosts(&req.Data)
if err := registry.Hosts().Register(req.Data.Name, v); err != nil {
if err := registry.HostsRegistry().Register(req.Data.Name, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -86,7 +86,7 @@ func updateHosts(ctx *gin.Context) {
ctx.ShouldBindUri(&req)
ctx.ShouldBindJSON(&req.Data)
if !registry.Hosts().IsRegistered(req.Hosts) {
if !registry.HostsRegistry().IsRegistered(req.Hosts) {
writeError(ctx, ErrNotFound)
return
}
@ -95,9 +95,9 @@ func updateHosts(ctx *gin.Context) {
v := parsing.ParseHosts(&req.Data)
registry.Hosts().Unregister(req.Hosts)
registry.HostsRegistry().Unregister(req.Hosts)
if err := registry.Hosts().Register(req.Hosts, v); err != nil {
if err := registry.HostsRegistry().Register(req.Hosts, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -143,11 +143,11 @@ func deleteHosts(ctx *gin.Context) {
var req deleteHostsRequest
ctx.ShouldBindUri(&req)
if !registry.Hosts().IsRegistered(req.Hosts) {
if !registry.HostsRegistry().IsRegistered(req.Hosts) {
writeError(ctx, ErrNotFound)
return
}
registry.Hosts().Unregister(req.Hosts)
registry.HostsRegistry().Unregister(req.Hosts)
cfg := config.Global()
hosts := cfg.Hosts

View File

@ -46,7 +46,7 @@ func createResolver(ctx *gin.Context) {
return
}
if err := registry.Resolver().Register(req.Data.Name, v); err != nil {
if err := registry.ResolverRegistry().Register(req.Data.Name, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -90,7 +90,7 @@ func updateResolver(ctx *gin.Context) {
ctx.ShouldBindUri(&req)
ctx.ShouldBindJSON(&req.Data)
if !registry.Resolver().IsRegistered(req.Resolver) {
if !registry.ResolverRegistry().IsRegistered(req.Resolver) {
writeError(ctx, ErrNotFound)
return
}
@ -103,9 +103,9 @@ func updateResolver(ctx *gin.Context) {
return
}
registry.Resolver().Unregister(req.Resolver)
registry.ResolverRegistry().Unregister(req.Resolver)
if err := registry.Resolver().Register(req.Resolver, v); err != nil {
if err := registry.ResolverRegistry().Register(req.Resolver, v); err != nil {
writeError(ctx, ErrDup)
return
}
@ -151,11 +151,11 @@ func deleteResolver(ctx *gin.Context) {
var req deleteResolverRequest
ctx.ShouldBindUri(&req)
if !registry.Resolver().IsRegistered(req.Resolver) {
if !registry.ResolverRegistry().IsRegistered(req.Resolver) {
writeError(ctx, ErrNotFound)
return
}
registry.Resolver().Unregister(req.Resolver)
registry.ResolverRegistry().Unregister(req.Resolver)
cfg := config.Global()
resolvers := cfg.Resolvers

View File

@ -40,7 +40,7 @@ func createService(ctx *gin.Context) {
return
}
if registry.Service().IsRegistered(req.Data.Name) {
if registry.ServiceRegistry().IsRegistered(req.Data.Name) {
writeError(ctx, ErrDup)
return
}
@ -51,7 +51,7 @@ func createService(ctx *gin.Context) {
return
}
if err := registry.Service().Register(req.Data.Name, svc); err != nil {
if err := registry.ServiceRegistry().Register(req.Data.Name, svc); err != nil {
svc.Close()
writeError(ctx, ErrDup)
return
@ -98,7 +98,7 @@ func updateService(ctx *gin.Context) {
ctx.ShouldBindUri(&req)
ctx.ShouldBindJSON(&req.Data)
old := registry.Service().Get(req.Service)
old := registry.ServiceRegistry().Get(req.Service)
if old == nil {
writeError(ctx, ErrNotFound)
return
@ -113,9 +113,9 @@ func updateService(ctx *gin.Context) {
return
}
registry.Service().Unregister(req.Service)
registry.ServiceRegistry().Unregister(req.Service)
if err := registry.Service().Register(req.Service, svc); err != nil {
if err := registry.ServiceRegistry().Register(req.Service, svc); err != nil {
svc.Close()
writeError(ctx, ErrDup)
return
@ -164,13 +164,13 @@ func deleteService(ctx *gin.Context) {
var req deleteServiceRequest
ctx.ShouldBindUri(&req)
svc := registry.Service().Get(req.Service)
svc := registry.ServiceRegistry().Get(req.Service)
if svc == nil {
writeError(ctx, ErrNotFound)
return
}
registry.Service().Unregister(req.Service)
registry.ServiceRegistry().Unregister(req.Service)
svc.Close()
cfg := config.Global()

View File

@ -17,7 +17,7 @@ func mwLogger() gin.HandlerFunc {
ctx.Next()
duration := time.Since(startTime)
logger.Default().WithFields(map[string]interface{}{
logger.Default().WithFields(map[string]any{
"kind": "api",
"method": ctx.Request.Method,
"uri": ctx.Request.RequestURI,

View File

@ -181,7 +181,7 @@ func (r *Route) bindLocal(ctx context.Context, network, address string, opts ...
if err != nil {
return nil, err
}
logger := logger.Default().WithFields(map[string]interface{}{
logger := logger.Default().WithFields(map[string]any{
"network": network,
"address": address,
})

View File

@ -10,7 +10,7 @@ var (
{
size: 128,
pool: sync.Pool{
New: func() interface{} {
New: func() any {
b := make([]byte, 128)
return &b
},
@ -19,7 +19,7 @@ var (
{
size: 512,
pool: sync.Pool{
New: func() interface{} {
New: func() any {
b := make([]byte, 512)
return &b
},
@ -28,7 +28,7 @@ var (
{
size: 1024,
pool: sync.Pool{
New: func() interface{} {
New: func() any {
b := make([]byte, 1024)
return &b
},
@ -37,7 +37,7 @@ var (
{
size: 4096,
pool: sync.Pool{
New: func() interface{} {
New: func() any {
b := make([]byte, 4096)
return &b
},
@ -46,7 +46,7 @@ var (
{
size: 8192,
pool: sync.Pool{
New: func() interface{} {
New: func() any {
b := make([]byte, 8192)
return &b
},
@ -55,7 +55,7 @@ var (
{
size: 16 * 1024,
pool: sync.Pool{
New: func() interface{} {
New: func() any {
b := make([]byte, 16*1024)
return &b
},
@ -64,7 +64,7 @@ var (
{
size: 32 * 1024,
pool: sync.Pool{
New: func() interface{} {
New: func() any {
b := make([]byte, 32*1024)
return &b
},
@ -73,7 +73,7 @@ var (
{
size: 64 * 1024,
pool: sync.Pool{
New: func() interface{} {
New: func() any {
b := make([]byte, 64*1024)
return &b
},
@ -82,7 +82,7 @@ var (
{
size: 65 * 1024,
pool: sync.Pool{
New: func() interface{} {
New: func() any {
b := make([]byte, 65*1024)
return &b
},

View File

@ -95,7 +95,7 @@ func file_gost_proto_rawDescGZIP() []byte {
}
var file_gost_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_gost_proto_goTypes = []interface{}{
var file_gost_proto_goTypes = []any{
(*Chunk)(nil), // 0: Chunk
}
var file_gost_proto_depIdxs = []int32{
@ -114,7 +114,7 @@ func file_gost_proto_init() {
return
}
if !protoimpl.UnsafeEnabled {
file_gost_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
file_gost_proto_msgTypes[0].Exporter = func(v any, i int) any {
switch v := v.(*Chunk); i {
case 0:
return &v.state

View File

@ -88,7 +88,7 @@ func RegisterGostTunelServer(s grpc.ServiceRegistrar, srv GostTunelServer) {
s.RegisterService(&GostTunel_ServiceDesc, srv)
}
func _GostTunel_Tunnel_Handler(srv interface{}, stream grpc.ServerStream) error {
func _GostTunel_Tunnel_Handler(srv any, stream grpc.ServerStream) error {
return srv.(GostTunelServer).Tunnel(&gostTunelTunnelServer{stream})
}

View File

@ -28,7 +28,7 @@ func (p *ConnPool) WithLogger(logger logger.Logger) *ConnPool {
return p
}
func (p *ConnPool) Get(key interface{}) (c *Conn, ok bool) {
func (p *ConnPool) Get(key any) (c *Conn, ok bool) {
v, ok := p.m.Load(key)
if ok {
c, ok = v.(*Conn)
@ -36,11 +36,11 @@ func (p *ConnPool) Get(key interface{}) (c *Conn, ok bool) {
return
}
func (p *ConnPool) Set(key interface{}, c *Conn) {
func (p *ConnPool) Set(key any, c *Conn) {
p.m.Store(key, c)
}
func (p *ConnPool) Delete(key interface{}) {
func (p *ConnPool) Delete(key any) {
p.m.Delete(key)
}
@ -53,7 +53,7 @@ func (p *ConnPool) Close() {
close(p.closed)
p.m.Range(func(k, v interface{}) bool {
p.m.Range(func(k, v any) bool {
if c, ok := v.(*Conn); ok && c != nil {
c.Close()
}
@ -70,7 +70,7 @@ func (p *ConnPool) idleCheck() {
case <-ticker.C:
size := 0
idles := 0
p.m.Range(func(key, value interface{}) bool {
p.m.Range(func(key, value any) bool {
c, ok := value.(*Conn)
if !ok || c == nil {
p.Delete(key)

View File

@ -140,22 +140,22 @@ type HostsConfig struct {
}
type ListenerConfig struct {
Type string `json:"type"`
Chain string `yaml:",omitempty" json:"chain,omitempty"`
Auther string `yaml:",omitempty" json:"auther,omitempty"`
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Metadata map[string]interface{} `yaml:",omitempty" json:"metadata,omitempty"`
Type string `json:"type"`
Chain string `yaml:",omitempty" json:"chain,omitempty"`
Auther string `yaml:",omitempty" json:"auther,omitempty"`
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Metadata map[string]any `yaml:",omitempty" json:"metadata,omitempty"`
}
type HandlerConfig struct {
Type string `json:"type"`
Retries int `yaml:",omitempty" json:"retries,omitempty"`
Chain string `yaml:",omitempty" json:"chain,omitempty"`
Auther string `yaml:",omitempty" json:"auther,omitempty"`
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Metadata map[string]interface{} `yaml:",omitempty" json:"metadata,omitempty"`
Type string `json:"type"`
Retries int `yaml:",omitempty" json:"retries,omitempty"`
Chain string `yaml:",omitempty" json:"chain,omitempty"`
Auther string `yaml:",omitempty" json:"auther,omitempty"`
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Metadata map[string]any `yaml:",omitempty" json:"metadata,omitempty"`
}
type ForwarderConfig struct {
@ -164,17 +164,17 @@ type ForwarderConfig struct {
}
type DialerConfig struct {
Type string `json:"type"`
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Metadata map[string]interface{} `yaml:",omitempty" json:"metadata,omitempty"`
Type string `json:"type"`
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Metadata map[string]any `yaml:",omitempty" json:"metadata,omitempty"`
}
type ConnectorConfig struct {
Type string `json:"type"`
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Metadata map[string]interface{} `yaml:",omitempty" json:"metadata,omitempty"`
Type string `json:"type"`
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Metadata map[string]any `yaml:",omitempty" json:"metadata,omitempty"`
}
type ServiceConfig struct {

View File

@ -16,7 +16,7 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
return nil, nil
}
chainLogger := logger.Default().WithFields(map[string]interface{}{
chainLogger := logger.Default().WithFields(map[string]any{
"kind": "chain",
"chain": cfg.Name,
})
@ -26,14 +26,14 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
for _, hop := range cfg.Hops {
group := &chain.NodeGroup{}
for _, v := range hop.Nodes {
nodeLogger := chainLogger.WithFields(map[string]interface{}{
nodeLogger := chainLogger.WithFields(map[string]any{
"kind": "node",
"connector": v.Connector.Type,
"dialer": v.Dialer.Type,
"hop": hop.Name,
"node": v.Name,
})
connectorLogger := nodeLogger.WithFields(map[string]interface{}{
connectorLogger := nodeLogger.WithFields(map[string]any{
"kind": "connector",
})
@ -49,21 +49,21 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
return nil, err
}
cr := registry.GetConnector(v.Connector.Type)(
cr := registry.ConnectorRegistry().Get(v.Connector.Type)(
connector.AuthOption(parseAuth(v.Connector.Auth)),
connector.TLSConfigOption(tlsConfig),
connector.LoggerOption(connectorLogger),
)
if v.Connector.Metadata == nil {
v.Connector.Metadata = make(map[string]interface{})
v.Connector.Metadata = make(map[string]any)
}
if err := cr.Init(metadata.MapMetadata(v.Connector.Metadata)); err != nil {
connectorLogger.Error("init: ", err)
return nil, err
}
dialerLogger := nodeLogger.WithFields(map[string]interface{}{
dialerLogger := nodeLogger.WithFields(map[string]any{
"kind": "dialer",
})
@ -79,14 +79,14 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
return nil, err
}
d := registry.GetDialer(v.Dialer.Type)(
d := registry.DialerRegistry().Get(v.Dialer.Type)(
dialer.AuthOption(parseAuth(v.Dialer.Auth)),
dialer.TLSConfigOption(tlsConfig),
dialer.LoggerOption(dialerLogger),
)
if v.Dialer.Metadata == nil {
v.Dialer.Metadata = make(map[string]interface{})
v.Dialer.Metadata = make(map[string]any)
}
if err := d.Init(metadata.MapMetadata(v.Dialer.Metadata)); err != nil {
dialerLogger.Error("init: ", err)
@ -112,9 +112,9 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
Name: v.Name,
Addr: v.Addr,
Transport: tr,
Bypass: registry.Bypass().Get(v.Bypass),
Resolver: registry.Resolver().Get(v.Resolver),
Hosts: registry.Hosts().Get(v.Hosts),
Bypass: registry.BypassRegistry().Get(v.Bypass),
Resolver: registry.ResolverRegistry().Get(v.Resolver),
Hosts: registry.HostsRegistry().Get(v.Hosts),
Marker: &chain.FailMarker{},
}
group.AddNode(node)

View File

@ -87,7 +87,7 @@ func ParseAdmission(cfg *config.AdmissionConfig) admission.Admission {
return admission.NewAdmissionPatterns(
cfg.Reverse,
cfg.Matchers,
admission.LoggerOption(logger.Default().WithFields(map[string]interface{}{
admission.LoggerOption(logger.Default().WithFields(map[string]any{
"kind": "admission",
"admission": cfg.Name,
})),
@ -101,7 +101,7 @@ func ParseBypass(cfg *config.BypassConfig) bypass.Bypass {
return bypass.NewBypassPatterns(
cfg.Reverse,
cfg.Matchers,
bypass.LoggerOption(logger.Default().WithFields(map[string]interface{}{
bypass.LoggerOption(logger.Default().WithFields(map[string]any{
"kind": "bypass",
"bypass": cfg.Name,
})),
@ -116,7 +116,7 @@ func ParseResolver(cfg *config.ResolverConfig) (resolver.Resolver, error) {
for _, server := range cfg.Nameservers {
nameservers = append(nameservers, resolver_impl.NameServer{
Addr: server.Addr,
Chain: registry.Chain().Get(server.Chain),
Chain: registry.ChainRegistry().Get(server.Chain),
TTL: server.TTL,
Timeout: server.Timeout,
ClientIP: net.ParseIP(server.ClientIP),
@ -128,7 +128,7 @@ func ParseResolver(cfg *config.ResolverConfig) (resolver.Resolver, error) {
return resolver_impl.NewResolver(
nameservers,
resolver_impl.LoggerResolverOption(
logger.Default().WithFields(map[string]interface{}{
logger.Default().WithFields(map[string]any{
"kind": "resolver",
"resolver": cfg.Name,
}),
@ -141,7 +141,7 @@ func ParseHosts(cfg *config.HostsConfig) hostspkg.HostMapper {
return nil
}
hosts := hostspkg.NewHosts()
hosts.Logger = logger.Default().WithFields(map[string]interface{}{
hosts.Logger = logger.Default().WithFields(map[string]any{
"kind": "hosts",
"hosts": cfg.Name,
})

View File

@ -25,14 +25,14 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
Type: "auto",
}
}
serviceLogger := logger.Default().WithFields(map[string]interface{}{
serviceLogger := logger.Default().WithFields(map[string]any{
"kind": "service",
"service": cfg.Name,
"listener": cfg.Listener.Type,
"handler": cfg.Handler.Type,
})
listenerLogger := serviceLogger.WithFields(map[string]interface{}{
listenerLogger := serviceLogger.WithFields(map[string]any{
"kind": "listener",
})
@ -49,12 +49,12 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
auther := ParseAutherFromAuth(cfg.Listener.Auth)
if cfg.Listener.Auther != "" {
auther = registry.Auther().Get(cfg.Listener.Auther)
auther = registry.AutherRegistry().Get(cfg.Listener.Auther)
}
ln := registry.GetListener(cfg.Listener.Type)(
ln := registry.ListenerRegistry().Get(cfg.Listener.Type)(
listener.AddrOption(cfg.Addr),
listener.ChainOption(registry.Chain().Get(cfg.Listener.Chain)),
listener.ChainOption(registry.ChainRegistry().Get(cfg.Listener.Chain)),
listener.AutherOption(auther),
listener.AuthOption(parseAuth(cfg.Listener.Auth)),
listener.TLSConfigOption(tlsConfig),
@ -62,14 +62,14 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
)
if cfg.Listener.Metadata == nil {
cfg.Listener.Metadata = make(map[string]interface{})
cfg.Listener.Metadata = make(map[string]any)
}
if err := ln.Init(metadata.MapMetadata(cfg.Listener.Metadata)); err != nil {
listenerLogger.Error("init: ", err)
return nil, err
}
handlerLogger := serviceLogger.WithFields(map[string]interface{}{
handlerLogger := serviceLogger.WithFields(map[string]any{
"kind": "handler",
})
@ -86,16 +86,16 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
auther = ParseAutherFromAuth(cfg.Handler.Auth)
if cfg.Handler.Auther != "" {
auther = registry.Auther().Get(cfg.Handler.Auther)
auther = registry.AutherRegistry().Get(cfg.Handler.Auther)
}
h := registry.GetHandler(cfg.Handler.Type)(
h := registry.HandlerRegistry().Get(cfg.Handler.Type)(
handler.AutherOption(auther),
handler.AuthOption(parseAuth(cfg.Handler.Auth)),
handler.RetriesOption(cfg.Handler.Retries),
handler.ChainOption(registry.Chain().Get(cfg.Handler.Chain)),
handler.BypassOption(registry.Bypass().Get(cfg.Bypass)),
handler.ResolverOption(registry.Resolver().Get(cfg.Resolver)),
handler.HostsOption(registry.Hosts().Get(cfg.Hosts)),
handler.ChainOption(registry.ChainRegistry().Get(cfg.Handler.Chain)),
handler.BypassOption(registry.BypassRegistry().Get(cfg.Bypass)),
handler.ResolverOption(registry.ResolverRegistry().Get(cfg.Resolver)),
handler.HostsOption(registry.HostsRegistry().Get(cfg.Hosts)),
handler.TLSConfigOption(tlsConfig),
handler.LoggerOption(handlerLogger),
)
@ -105,7 +105,7 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
}
if cfg.Handler.Metadata == nil {
cfg.Handler.Metadata = make(map[string]interface{})
cfg.Handler.Metadata = make(map[string]any)
}
if err := h.Init(metadata.MapMetadata(cfg.Handler.Metadata)); err != nil {
handlerLogger.Error("init: ", err)
@ -113,7 +113,7 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
}
s := service.NewService(ln, h,
service.AdmissionOption(registry.Admission().Get(cfg.Admission)),
service.AdmissionOption(registry.AdmissionRegistry().Get(cfg.Admission)),
service.LoggerOption(serviceLogger),
)

View File

@ -10,7 +10,7 @@ import (
)
func init() {
registry.RegiserConnector("forward", NewConnector)
registry.ConnectorRegistry().Register("forward", NewConnector)
}
type forwardConnector struct {
@ -33,7 +33,7 @@ func (c *forwardConnector) Init(md md.Metadata) (err error) {
}
func (c *forwardConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,

View File

@ -19,7 +19,7 @@ import (
)
func init() {
registry.RegiserConnector("http", NewConnector)
registry.ConnectorRegistry().Register("http", NewConnector)
}
type httpConnector struct {
@ -43,7 +43,7 @@ func (c *httpConnector) Init(md md.Metadata) (err error) {
}
func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"local": conn.LocalAddr().String(),
"remote": conn.RemoteAddr().String(),
"network": network,

View File

@ -20,7 +20,7 @@ import (
)
func init() {
registry.RegiserConnector("http2", NewConnector)
registry.ConnectorRegistry().Register("http2", NewConnector)
}
type http2Connector struct {
@ -44,7 +44,7 @@ func (c *http2Connector) Init(md md.Metadata) (err error) {
}
func (c *http2Connector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"local": conn.LocalAddr().String(),
"remote": conn.RemoteAddr().String(),
"network": network,

View File

@ -16,7 +16,7 @@ import (
// Bind implements connector.Binder.
func (c *relayConnector) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"network": network,
"address": address,
})

View File

@ -14,7 +14,7 @@ import (
)
func init() {
registry.RegiserConnector("relay", NewConnector)
registry.ConnectorRegistry().Register("relay", NewConnector)
}
type relayConnector struct {
@ -38,7 +38,7 @@ func (c *relayConnector) Init(md md.Metadata) (err error) {
}
func (c *relayConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,

View File

@ -10,7 +10,7 @@ import (
)
func init() {
registry.RegiserConnector("sni", NewConnector)
registry.ConnectorRegistry().Register("sni", NewConnector)
}
type sniConnector struct {
@ -34,7 +34,7 @@ func (c *sniConnector) Init(md md.Metadata) (err error) {
}
func (c *sniConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,

View File

@ -15,8 +15,8 @@ import (
)
func init() {
registry.RegiserConnector("socks4", NewConnector)
registry.RegiserConnector("socks4a", NewConnector)
registry.ConnectorRegistry().Register("socks4", NewConnector)
registry.ConnectorRegistry().Register("socks4a", NewConnector)
}
type socks4Connector struct {
@ -40,7 +40,7 @@ func (c *socks4Connector) Init(md md.Metadata) (err error) {
}
func (c *socks4Connector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,

View File

@ -15,7 +15,7 @@ import (
// Bind implements connector.Binder.
func (c *socks5Connector) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,

View File

@ -17,8 +17,8 @@ import (
)
func init() {
registry.RegiserConnector("socks5", NewConnector)
registry.RegiserConnector("socks", NewConnector)
registry.ConnectorRegistry().Register("socks5", NewConnector)
registry.ConnectorRegistry().Register("socks", NewConnector)
}
type socks5Connector struct {
@ -67,7 +67,7 @@ func (c *socks5Connector) Init(md md.Metadata) (err error) {
// Handshake implements connector.Handshaker.
func (c *socks5Connector) Handshake(ctx context.Context, conn net.Conn) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
@ -87,7 +87,7 @@ func (c *socks5Connector) Handshake(ctx context.Context, conn net.Conn) (net.Con
}
func (c *socks5Connector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,

View File

@ -16,7 +16,7 @@ import (
)
func init() {
registry.RegiserConnector("ss", NewConnector)
registry.ConnectorRegistry().Register("ss", NewConnector)
}
type ssConnector struct {
@ -51,7 +51,7 @@ func (c *ssConnector) Init(md md.Metadata) (err error) {
}
func (c *ssConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,

View File

@ -15,7 +15,7 @@ import (
)
func init() {
registry.RegiserConnector("ssu", NewConnector)
registry.ConnectorRegistry().Register("ssu", NewConnector)
}
type ssuConnector struct {
@ -50,7 +50,7 @@ func (c *ssuConnector) Init(md md.Metadata) (err error) {
}
func (c *ssuConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,

View File

@ -12,7 +12,7 @@ import (
)
func init() {
registry.RegiserConnector("sshd", NewConnector)
registry.ConnectorRegistry().Register("sshd", NewConnector)
}
type sshdConnector struct {
@ -35,7 +35,7 @@ func (c *sshdConnector) Init(md md.Metadata) (err error) {
}
func (c *sshdConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,
@ -59,7 +59,7 @@ func (c *sshdConnector) Connect(ctx context.Context, conn net.Conn, network, add
// Bind implements connector.Binder.
func (c *sshdConnector) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error) {
log := c.options.Logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,

View File

@ -12,7 +12,7 @@ import (
)
func init() {
registry.RegisterDialer("ftcp", NewDialer)
registry.DialerRegistry().Register("ftcp", NewDialer)
}
type ftcpDialer struct {

View File

@ -17,7 +17,7 @@ import (
)
func init() {
registry.RegisterDialer("grpc", NewDialer)
registry.DialerRegistry().Register("grpc", NewDialer)
}
type grpcDialer struct {
@ -119,7 +119,7 @@ func (d *grpcDialer) dial(ctx context.Context, network, addr string, opts *diale
if err != nil {
d.options.Logger.Error(err)
} else {
d.options.Logger.WithFields(map[string]interface{}{
d.options.Logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debug("dial with dial func")
@ -132,7 +132,7 @@ func (d *grpcDialer) dial(ctx context.Context, network, addr string, opts *diale
if err != nil {
d.options.Logger.Error(err)
} else {
d.options.Logger.WithFields(map[string]interface{}{
d.options.Logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debugf("dial direct %s/%s", addr, network)

View File

@ -15,7 +15,7 @@ import (
)
func init() {
registry.RegisterDialer("http2", NewDialer)
registry.DialerRegistry().Register("http2", NewDialer)
}
type http2Dialer struct {
@ -102,7 +102,7 @@ func (d *http2Dialer) dial(ctx context.Context, network, addr string, opts *dial
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debug("dial with dial func")
@ -115,7 +115,7 @@ func (d *http2Dialer) dial(ctx context.Context, network, addr string, opts *dial
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debugf("dial direct %s/%s", addr, network)

View File

@ -20,8 +20,8 @@ import (
)
func init() {
registry.RegisterDialer("h2", NewTLSDialer)
registry.RegisterDialer("h2c", NewDialer)
registry.DialerRegistry().Register("h2", NewTLSDialer)
registry.DialerRegistry().Register("h2c", NewDialer)
}
type h2Dialer struct {
@ -171,7 +171,7 @@ func (d *h2Dialer) dial(ctx context.Context, network, addr string, opts *dialer.
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debug("dial with dial func")
@ -184,7 +184,7 @@ func (d *h2Dialer) dial(ctx context.Context, network, addr string, opts *dialer.
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debugf("dial direct %s/%s", addr, network)

View File

@ -14,8 +14,8 @@ import (
)
func init() {
registry.RegisterDialer("http3", NewDialer)
registry.RegisterDialer("h3", NewDialer)
registry.DialerRegistry().Register("http3", NewDialer)
registry.DialerRegistry().Register("h3", NewDialer)
}
type http3Dialer struct {

View File

@ -18,7 +18,7 @@ import (
)
func init() {
registry.RegisterDialer("kcp", NewDialer)
registry.DialerRegistry().Register("kcp", NewDialer)
}
type kcpDialer struct {

View File

@ -11,7 +11,7 @@ import (
)
func init() {
registry.RegisterDialer("ohttp", NewDialer)
registry.DialerRegistry().Register("ohttp", NewDialer)
}
type obfsHTTPDialer struct {

View File

@ -11,7 +11,7 @@ import (
)
func init() {
registry.RegisterDialer("otls", NewDialer)
registry.DialerRegistry().Register("otls", NewDialer)
}
type obfsTLSDialer struct {

View File

@ -14,8 +14,8 @@ import (
)
func init() {
registry.RegisterDialer("pht", NewDialer)
registry.RegisterDialer("phts", NewTLSDialer)
registry.DialerRegistry().Register("pht", NewDialer)
registry.DialerRegistry().Register("phts", NewTLSDialer)
}
type phtDialer struct {

View File

@ -16,7 +16,7 @@ import (
)
func init() {
registry.RegisterDialer("quic", NewDialer)
registry.DialerRegistry().Register("quic", NewDialer)
}
type quicDialer struct {

View File

@ -16,7 +16,7 @@ import (
)
func init() {
registry.RegisterDialer("ssh", NewDialer)
registry.DialerRegistry().Register("ssh", NewDialer)
}
type sshDialer struct {
@ -141,7 +141,7 @@ func (d *sshDialer) dial(ctx context.Context, network, addr string, opts *dialer
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debug("dial with dial func")
@ -154,7 +154,7 @@ func (d *sshDialer) dial(ctx context.Context, network, addr string, opts *dialer
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debugf("dial direct %s/%s", addr, network)

View File

@ -15,7 +15,7 @@ import (
)
func init() {
registry.RegisterDialer("sshd", NewDialer)
registry.DialerRegistry().Register("sshd", NewDialer)
}
type sshdDialer struct {
@ -138,7 +138,7 @@ func (d *sshdDialer) dial(ctx context.Context, network, addr string, opts *diale
if err != nil {
log.Error(err)
} else {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debug("dial with dial func")
@ -151,7 +151,7 @@ func (d *sshdDialer) dial(ctx context.Context, network, addr string, opts *diale
if err != nil {
log.Error(err)
} else {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debugf("dial direct %s/%s", addr, network)

View File

@ -11,7 +11,7 @@ import (
)
func init() {
registry.RegisterDialer("tcp", NewDialer)
registry.DialerRegistry().Register("tcp", NewDialer)
}
type tcpDialer struct {

View File

@ -13,7 +13,7 @@ import (
)
func init() {
registry.RegisterDialer("tls", NewDialer)
registry.DialerRegistry().Register("tls", NewDialer)
}
type tlsDialer struct {

View File

@ -16,7 +16,7 @@ import (
)
func init() {
registry.RegisterDialer("mtls", NewDialer)
registry.DialerRegistry().Register("mtls", NewDialer)
}
type mtlsDialer struct {
@ -129,7 +129,7 @@ func (d *mtlsDialer) dial(ctx context.Context, network, addr string, opts *diale
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debug("dial with dial func")
@ -142,7 +142,7 @@ func (d *mtlsDialer) dial(ctx context.Context, network, addr string, opts *diale
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debugf("dial direct %s/%s", addr, network)

View File

@ -11,7 +11,7 @@ import (
)
func init() {
registry.RegisterDialer("udp", NewDialer)
registry.DialerRegistry().Register("udp", NewDialer)
}
type udpDialer struct {

View File

@ -15,8 +15,8 @@ import (
)
func init() {
registry.RegisterDialer("ws", NewDialer)
registry.RegisterDialer("wss", NewTLSDialer)
registry.DialerRegistry().Register("ws", NewDialer)
registry.DialerRegistry().Register("wss", NewTLSDialer)
}
type wsDialer struct {

View File

@ -18,8 +18,8 @@ import (
)
func init() {
registry.RegisterDialer("mws", NewDialer)
registry.RegisterDialer("mwss", NewTLSDialer)
registry.DialerRegistry().Register("mws", NewDialer)
registry.DialerRegistry().Register("mwss", NewTLSDialer)
}
type mwsDialer struct {
@ -150,7 +150,7 @@ func (d *mwsDialer) dial(ctx context.Context, network, addr string, opts *dialer
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debug("dial with dial func")
@ -163,7 +163,7 @@ func (d *mwsDialer) dial(ctx context.Context, network, addr string, opts *dialer
if err != nil {
d.logger.Error(err)
} else {
d.logger.WithFields(map[string]interface{}{
d.logger.WithFields(map[string]any{
"src": conn.LocalAddr().String(),
"dst": addr,
}).Debugf("dial direct %s/%s", addr, network)

View File

@ -15,7 +15,7 @@ import (
)
func init() {
registry.RegisterHandler("auto", NewHandler)
registry.HandlerRegistry().Register("auto", NewHandler)
}
type autoHandler struct {
@ -36,24 +36,24 @@ func NewHandler(opts ...handler.Option) handler.Handler {
options: options,
}
if f := registry.GetHandler("http"); f != nil {
if f := registry.HandlerRegistry().Get("http"); f != nil {
v := append(opts,
handler.LoggerOption(options.Logger.WithFields(map[string]interface{}{"type": "http"})))
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "http"})))
h.httpHandler = f(v...)
}
if f := registry.GetHandler("socks4"); f != nil {
if f := registry.HandlerRegistry().Get("socks4"); f != nil {
v := append(opts,
handler.LoggerOption(options.Logger.WithFields(map[string]interface{}{"type": "socks4"})))
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "socks4"})))
h.socks4Handler = f(v...)
}
if f := registry.GetHandler("socks5"); f != nil {
if f := registry.HandlerRegistry().Get("socks5"); f != nil {
v := append(opts,
handler.LoggerOption(options.Logger.WithFields(map[string]interface{}{"type": "socks5"})))
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "socks5"})))
h.socks5Handler = f(v...)
}
if f := registry.GetHandler("relay"); f != nil {
if f := registry.HandlerRegistry().Get("relay"); f != nil {
v := append(opts,
handler.LoggerOption(options.Logger.WithFields(map[string]interface{}{"type": "relay"})))
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "relay"})))
h.relayHandler = f(v...)
}
@ -86,7 +86,7 @@ func (h *autoHandler) Init(md md.Metadata) error {
}
func (h *autoHandler) Handle(ctx context.Context, conn net.Conn) {
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
@ -94,7 +94,7 @@ func (h *autoHandler) Handle(ctx context.Context, conn net.Conn) {
start := time.Now()
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()

View File

@ -26,7 +26,7 @@ const (
)
func init() {
registry.RegisterHandler("dns", NewHandler)
registry.HandlerRegistry().Register("dns", NewHandler)
}
type dnsHandler struct {
@ -101,14 +101,14 @@ func (h *dnsHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()

View File

@ -13,9 +13,9 @@ import (
)
func init() {
registry.RegisterHandler("tcp", NewHandler)
registry.RegisterHandler("udp", NewHandler)
registry.RegisterHandler("forward", NewHandler)
registry.HandlerRegistry().Register("tcp", NewHandler)
registry.HandlerRegistry().Register("udp", NewHandler)
registry.HandlerRegistry().Register("forward", NewHandler)
}
type forwardHandler struct {
@ -66,14 +66,14 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -89,7 +89,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
network = "udp"
}
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
})
@ -109,7 +109,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
}

View File

@ -13,8 +13,8 @@ import (
)
func init() {
registry.RegisterHandler("rtcp", NewHandler)
registry.RegisterHandler("rudp", NewHandler)
registry.HandlerRegistry().Register("rtcp", NewHandler)
registry.HandlerRegistry().Register("rudp", NewHandler)
}
type forwardHandler struct {
@ -60,14 +60,14 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -83,7 +83,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
network = "udp"
}
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
})
@ -103,7 +103,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
}

View File

@ -24,7 +24,7 @@ import (
)
func init() {
registry.RegisterHandler("http", NewHandler)
registry.HandlerRegistry().Register("http", NewHandler)
}
type httpHandler struct {
@ -64,13 +64,13 @@ func (h *httpHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -120,7 +120,7 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
addr = net.JoinHostPort(addr, "80")
}
fields := map[string]interface{}{
fields := map[string]any{
"dst": addr,
}
if u, _, _ := h.basicProxyAuth(req.Header.Get("Proxy-Authorization"), log); u != "" {
@ -216,7 +216,7 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
start := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
}

View File

@ -13,7 +13,7 @@ import (
)
func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"cmd": "udp",
})
@ -70,7 +70,7 @@ func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, network, add
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
relay.Run()
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
}

View File

@ -27,7 +27,7 @@ import (
)
func init() {
registry.RegisterHandler("http2", NewHandler)
registry.HandlerRegistry().Register("http2", NewHandler)
}
type http2Handler struct {
@ -66,13 +66,13 @@ func (h *http2Handler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -110,7 +110,7 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
addr = net.JoinHostPort(addr, "80")
}
fields := map[string]interface{}{
fields := map[string]any{
"dst": addr,
}
if u, _, _ := h.basicProxyAuth(req.Header.Get("Proxy-Authorization")); u != "" {
@ -177,7 +177,7 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
start := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
@ -187,7 +187,7 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
start := time.Now()
log.Infof("%s <-> %s", req.RemoteAddr, addr)
handler.Transport(&readWriter{r: req.Body, w: flushWriter{w}}, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >-< %s", req.RemoteAddr, addr)
return

View File

@ -13,10 +13,10 @@ import (
)
func init() {
registry.RegisterHandler("red", NewHandler)
registry.RegisterHandler("redu", NewHandler)
registry.RegisterHandler("redir", NewHandler)
registry.RegisterHandler("redirect", NewHandler)
registry.HandlerRegistry().Register("red", NewHandler)
registry.HandlerRegistry().Register("redu", NewHandler)
registry.HandlerRegistry().Register("redir", NewHandler)
registry.HandlerRegistry().Register("redirect", NewHandler)
}
type redirectHandler struct {
@ -56,14 +56,14 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -85,7 +85,7 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn) {
}
}
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", dstAddr, network),
})
@ -106,7 +106,7 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn) {
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), dstAddr)
}

View File

@ -14,7 +14,7 @@ import (
)
func (h *relayHandler) handleBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", address, network),
"cmd": "bind",
})
@ -70,7 +70,7 @@ func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, addr
return
}
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
})
log.Debugf("bind on %s OK", ln.Addr())
@ -107,7 +107,7 @@ func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, addr
return
}
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"bind": pc.LocalAddr().String(),
})
log.Debugf("bind on %s OK", pc.LocalAddr())
@ -120,7 +120,7 @@ func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, addr
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
relay.Run()
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
}
@ -157,7 +157,7 @@ func (h *relayHandler) serveTCPBind(ctx context.Context, conn net.Conn, ln net.L
go func(c net.Conn) {
defer c.Close()
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"local": ln.Addr().String(),
"remote": c.RemoteAddr().String(),
})
@ -184,7 +184,7 @@ func (h *relayHandler) serveTCPBind(ctx context.Context, conn net.Conn, ln net.L
t := time.Now()
log.Infof("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
handler.Transport(sc, c)
log.WithFields(map[string]interface{}{"duration": time.Since(t)}).
log.WithFields(map[string]any{"duration": time.Since(t)}).
Infof("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
}(rc)
}

View File

@ -12,7 +12,7 @@ import (
)
func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", address, network),
"cmd": "connect",
})
@ -81,7 +81,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
}

View File

@ -24,7 +24,7 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
return
}
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
"cmd": "forward",
})
@ -81,7 +81,7 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
}

View File

@ -14,7 +14,7 @@ import (
)
func init() {
registry.RegisterHandler("relay", NewHandler)
registry.HandlerRegistry().Register("relay", NewHandler)
}
type relayHandler struct {
@ -59,14 +59,14 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -102,7 +102,7 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn) {
}
if user != "" {
log = log.WithFields(map[string]interface{}{"user": user})
log = log.WithFields(map[string]any{"user": user})
}
resp := relay.Response{

View File

@ -20,7 +20,7 @@ import (
)
func init() {
registry.RegisterHandler("sni", NewHandler)
registry.HandlerRegistry().Register("sni", NewHandler)
}
type sniHandler struct {
@ -40,9 +40,9 @@ func NewHandler(opts ...handler.Option) handler.Handler {
options: options,
}
if f := registry.GetHandler("http"); f != nil {
if f := registry.HandlerRegistry().Get("http"); f != nil {
v := append(opts,
handler.LoggerOption(h.options.Logger.WithFields(map[string]interface{}{"type": "http"})))
handler.LoggerOption(h.options.Logger.WithFields(map[string]any{"type": "http"})))
h.httpHandler = f(v...)
}
@ -77,14 +77,14 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -125,7 +125,7 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn) {
}
target := net.JoinHostPort(host, "443")
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": target,
})
log.Infof("%s >> %s", conn.RemoteAddr(), target)
@ -149,7 +149,7 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn) {
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), target)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), target)
}

View File

@ -14,8 +14,8 @@ import (
)
func init() {
registry.RegisterHandler("socks4", NewHandler)
registry.RegisterHandler("socks4a", NewHandler)
registry.HandlerRegistry().Register("socks4", NewHandler)
registry.HandlerRegistry().Register("socks4a", NewHandler)
}
type socks4Handler struct {
@ -56,14 +56,14 @@ func (h *socks4Handler) Handle(ctx context.Context, conn net.Conn) {
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -102,7 +102,7 @@ func (h *socks4Handler) Handle(ctx context.Context, conn net.Conn) {
func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *gosocks4.Request, log logger.Logger) {
addr := req.Addr.String()
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": addr,
})
log.Infof("%s >> %s", conn.RemoteAddr(), addr)
@ -135,7 +135,7 @@ func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *g
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
}

View File

@ -12,7 +12,7 @@ import (
)
func (h *socks5Handler) handleBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", address, network),
"cmd": "bind",
})
@ -59,7 +59,7 @@ func (h *socks5Handler) bindLocal(ctx context.Context, conn net.Conn, network, a
}
log.Debug(reply)
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
})
@ -120,7 +120,7 @@ func (h *socks5Handler) serveBind(ctx context.Context, conn net.Conn, ln net.Lis
log.Debugf("peer %s accepted", rc.RemoteAddr())
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"local": rc.LocalAddr().String(),
"remote": rc.RemoteAddr().String(),
})
@ -136,7 +136,7 @@ func (h *socks5Handler) serveBind(ctx context.Context, conn net.Conn, ln net.Lis
start := time.Now()
log.Infof("%s <-> %s", rc.LocalAddr(), rc.RemoteAddr())
handler.Transport(pc2, rc)
log.WithFields(map[string]interface{}{"duration": time.Since(start)}).
log.WithFields(map[string]any{"duration": time.Since(start)}).
Infof("%s >-< %s", rc.LocalAddr(), rc.RemoteAddr())
case err := <-pipe():

View File

@ -12,7 +12,7 @@ import (
)
func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", address, network),
"cmd": "connect",
})
@ -46,7 +46,7 @@ func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, networ
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
}

View File

@ -14,8 +14,8 @@ import (
)
func init() {
registry.RegisterHandler("socks5", NewHandler)
registry.RegisterHandler("socks", NewHandler)
registry.HandlerRegistry().Register("socks5", NewHandler)
registry.HandlerRegistry().Register("socks", NewHandler)
}
type socks5Handler struct {
@ -64,14 +64,14 @@ func (h *socks5Handler) Handle(ctx context.Context, conn net.Conn) {
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()

View File

@ -13,7 +13,7 @@ import (
)
func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", address, network),
"cmd": "mbind",
})
@ -60,7 +60,7 @@ func (h *socks5Handler) muxBindLocal(ctx context.Context, conn net.Conn, network
}
log.Debug(reply)
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
})
@ -101,7 +101,7 @@ func (h *socks5Handler) serveMuxBind(ctx context.Context, conn net.Conn, ln net.
go func(c net.Conn) {
defer c.Close()
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"local": rc.LocalAddr().String(),
"remote": rc.RemoteAddr().String(),
})
@ -127,7 +127,7 @@ func (h *socks5Handler) serveMuxBind(ctx context.Context, conn net.Conn, ln net.
t := time.Now()
log.Infof("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
handler.Transport(sc, c)
log.WithFields(map[string]interface{}{"duration": time.Since(t)}).
log.WithFields(map[string]any{"duration": time.Since(t)}).
Infof("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
}(rc)
}

View File

@ -15,7 +15,7 @@ import (
)
func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger.Logger) {
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"cmd": "udp",
})
@ -48,7 +48,7 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger
}
log.Debug(reply)
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"bind": fmt.Sprintf("%s/%s", cc.LocalAddr(), cc.LocalAddr().Network()),
})
log.Debugf("bind on %s OK", cc.LocalAddr())
@ -77,6 +77,6 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), cc.LocalAddr())
io.Copy(ioutil.Discard, conn)
log.WithFields(map[string]interface{}{"duration": time.Since(t)}).
log.WithFields(map[string]any{"duration": time.Since(t)}).
Infof("%s >-< %s", conn.RemoteAddr(), cc.LocalAddr())
}

View File

@ -12,7 +12,7 @@ import (
)
func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"cmd": "udp-tun",
})
@ -66,7 +66,7 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
relay.Run()
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
}

View File

@ -17,7 +17,7 @@ import (
)
func init() {
registry.RegisterHandler("ss", NewHandler)
registry.HandlerRegistry().Register("ss", NewHandler)
}
type ssHandler struct {
@ -66,14 +66,14 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -93,7 +93,7 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn) {
return
}
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": addr.String(),
})
@ -113,7 +113,7 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn) {
t := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
}

View File

@ -17,7 +17,7 @@ import (
)
func init() {
registry.RegisterHandler("ssu", NewHandler)
registry.HandlerRegistry().Register("ssu", NewHandler)
}
type ssuHandler struct {
@ -67,14 +67,14 @@ func (h *ssuHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -111,7 +111,7 @@ func (h *ssuHandler) Handle(ctx context.Context, conn net.Conn) {
t := time.Now()
log.Infof("%s <-> %s", conn.LocalAddr(), cc.LocalAddr())
h.relayPacket(pc, cc, log)
log.WithFields(map[string]interface{}{"duration": time.Since(t)}).
log.WithFields(map[string]any{"duration": time.Since(t)}).
Infof("%s >-< %s", conn.LocalAddr(), cc.LocalAddr())
}

View File

@ -23,7 +23,7 @@ const (
)
func init() {
registry.RegisterHandler("sshd", NewHandler)
registry.HandlerRegistry().Register("sshd", NewHandler)
}
type forwardHandler struct {
@ -62,7 +62,7 @@ func (h *forwardHandler) Init(md md.Metadata) (err error) {
func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
log := h.options.Logger.WithFields(map[string]interface{}{
log := h.options.Logger.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
@ -81,7 +81,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
func (h *forwardHandler) handleDirectForward(ctx context.Context, conn *sshd_util.DirectForwardConn, log logger.Logger) {
targetAddr := conn.DstAddr()
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", targetAddr, "tcp"),
"cmd": "connect",
})
@ -102,7 +102,7 @@ func (h *forwardHandler) handleDirectForward(ctx context.Context, conn *sshd_uti
t := time.Now()
log.Infof("%s <-> %s", cc.LocalAddr(), targetAddr)
handler.Transport(conn, cc)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", cc.LocalAddr(), targetAddr)
}
@ -116,7 +116,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
network := "tcp"
addr := net.JoinHostPort(t.Host, strconv.Itoa(int(t.Port)))
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", addr, network),
"cmd": "bind",
})
@ -132,7 +132,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
}
defer ln.Close()
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
})
log.Debugf("bind on %s OK", ln.Addr())
@ -167,7 +167,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
go func(conn net.Conn) {
defer conn.Close()
log := log.WithFields(map[string]interface{}{
log := log.WithFields(map[string]any{
"local": conn.LocalAddr().String(),
"remote": conn.RemoteAddr().String(),
})
@ -195,7 +195,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
t := time.Now()
log.Infof("%s <-> %s", conn.LocalAddr(), conn.RemoteAddr())
handler.Transport(ch, conn)
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.LocalAddr(), conn.RemoteAddr())
}(cc)
@ -205,7 +205,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
tm := time.Now()
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
<-conn.Done()
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(tm),
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
}

View File

@ -24,7 +24,7 @@ import (
)
func init() {
registry.RegisterHandler("tap", NewHandler)
registry.HandlerRegistry().Register("tap", NewHandler)
}
type tapHandler struct {
@ -91,14 +91,14 @@ func (h *tapHandler) Handle(ctx context.Context, conn net.Conn) {
}
start := time.Now()
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -114,7 +114,7 @@ func (h *tapHandler) Handle(ctx context.Context, conn net.Conn) {
log.Error(err)
return
}
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", raddr.String(), raddr.Network()),
})
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
@ -214,7 +214,7 @@ func (h *tapHandler) transport(tap net.Conn, conn net.PacketConn, raddr net.Addr
// server side, broadcast.
if waterutil.IsBroadcast(dst) {
go h.routes.Range(func(k, v interface{}) bool {
go h.routes.Range(func(k, v any) bool {
conn.WriteTo((*b)[:n], v.(net.Addr))
return true
})
@ -281,7 +281,7 @@ func (h *tapHandler) transport(tap net.Conn, conn net.PacketConn, raddr net.Addr
}
if waterutil.IsBroadcast(dst) {
go h.routes.Range(func(k, v interface{}) bool {
go h.routes.Range(func(k, v any) bool {
if k.(tapRouteKey) != rkey {
conn.WriteTo((*b)[:n], v.(net.Addr))
}

View File

@ -26,7 +26,7 @@ import (
)
func init() {
registry.RegisterHandler("tun", NewHandler)
registry.HandlerRegistry().Register("tun", NewHandler)
}
type tunHandler struct {
@ -94,14 +94,14 @@ func (h *tunHandler) Handle(ctx context.Context, conn net.Conn) {
}
start := time.Now()
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
log.WithFields(map[string]interface{}{
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()
@ -117,7 +117,7 @@ func (h *tunHandler) Handle(ctx context.Context, conn net.Conn) {
log.Error(err)
return
}
log = log.WithFields(map[string]interface{}{
log = log.WithFields(map[string]any{
"dst": fmt.Sprintf("%s/%s", raddr.String(), raddr.Network()),
})
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)

View File

@ -17,7 +17,7 @@ import (
)
func init() {
registry.RegisterListener("dns", NewListener)
registry.ListenerRegistry().Register("dns", NewListener)
}
type dnsListener struct {

View File

@ -13,7 +13,7 @@ import (
)
func init() {
registry.RegisterListener("ftcp", NewListener)
registry.ListenerRegistry().Register("ftcp", NewListener)
}
type ftcpListener struct {
@ -69,7 +69,7 @@ func (l *ftcpListener) Accept() (conn net.Conn, err error) {
func (l *ftcpListener) Close() error {
err := l.conn.Close()
l.connPool.Range(func(k interface{}, v *serverConn) bool {
l.connPool.Range(func(k any, v *serverConn) bool {
v.Close()
return true
})
@ -128,7 +128,7 @@ type connPool struct {
m sync.Map
}
func (p *connPool) Get(key interface{}) (conn *serverConn, ok bool) {
func (p *connPool) Get(key any) (conn *serverConn, ok bool) {
v, ok := p.m.Load(key)
if ok {
conn, ok = v.(*serverConn)
@ -136,18 +136,18 @@ func (p *connPool) Get(key interface{}) (conn *serverConn, ok bool) {
return
}
func (p *connPool) Set(key interface{}, conn *serverConn) {
func (p *connPool) Set(key any, conn *serverConn) {
p.m.Store(key, conn)
atomic.AddInt64(&p.size, 1)
}
func (p *connPool) Delete(key interface{}) {
func (p *connPool) Delete(key any) {
p.m.Delete(key)
atomic.AddInt64(&p.size, -1)
}
func (p *connPool) Range(f func(key interface{}, value *serverConn) bool) {
p.m.Range(func(k, v interface{}) bool {
func (p *connPool) Range(f func(key any, value *serverConn) bool) {
p.m.Range(func(k, v any) bool {
return f(k, v.(*serverConn))
})
}

View File

@ -13,7 +13,7 @@ import (
)
func init() {
registry.RegisterListener("grpc", NewListener)
registry.ListenerRegistry().Register("grpc", NewListener)
}
type grpcListener struct {

View File

@ -16,8 +16,8 @@ import (
)
func init() {
registry.RegisterListener("h2c", NewListener)
registry.RegisterListener("h2", NewTLSListener)
registry.ListenerRegistry().Register("h2c", NewListener)
registry.ListenerRegistry().Register("h2", NewTLSListener)
}
type h2Listener struct {

View File

@ -15,7 +15,7 @@ import (
)
func init() {
registry.RegisterListener("http2", NewListener)
registry.ListenerRegistry().Register("http2", NewListener)
}
type http2Listener struct {

View File

@ -12,8 +12,8 @@ import (
)
func init() {
registry.RegisterListener("http3", NewListener)
registry.RegisterListener("h3", NewListener)
registry.ListenerRegistry().Register("http3", NewListener)
registry.ListenerRegistry().Register("h3", NewListener)
}
type http3Listener struct {

View File

@ -15,7 +15,7 @@ import (
)
func init() {
registry.RegisterListener("kcp", NewListener)
registry.ListenerRegistry().Register("kcp", NewListener)
}
type kcpListener struct {

View File

@ -10,7 +10,7 @@ import (
)
func init() {
registry.RegisterListener("ohttp", NewListener)
registry.ListenerRegistry().Register("ohttp", NewListener)
}
type obfsListener struct {

View File

@ -10,7 +10,7 @@ import (
)
func init() {
registry.RegisterListener("otls", NewListener)
registry.ListenerRegistry().Register("otls", NewListener)
}
type obfsListener struct {

View File

@ -13,8 +13,8 @@ import (
)
func init() {
registry.RegisterListener("pht", NewListener)
registry.RegisterListener("phts", NewTLSListener)
registry.ListenerRegistry().Register("pht", NewListener)
registry.ListenerRegistry().Register("phts", NewTLSListener)
}
type phtListener struct {

View File

@ -13,7 +13,7 @@ import (
)
func init() {
registry.RegisterListener("quic", NewListener)
registry.ListenerRegistry().Register("quic", NewListener)
}
type quicListener struct {

View File

@ -10,7 +10,7 @@ import (
)
func init() {
registry.RegisterListener("redu", NewListener)
registry.ListenerRegistry().Register("redu", NewListener)
}
type redirectListener struct {

View File

@ -13,7 +13,7 @@ import (
)
func init() {
registry.RegisterListener("rtcp", NewListener)
registry.ListenerRegistry().Register("rtcp", NewListener)
}
type rtcpListener struct {

View File

@ -13,7 +13,7 @@ import (
)
func init() {
registry.RegisterListener("rudp", NewListener)
registry.ListenerRegistry().Register("rudp", NewListener)
}
type rudpListener struct {

View File

@ -14,7 +14,7 @@ import (
)
func init() {
registry.RegisterListener("ssh", NewListener)
registry.ListenerRegistry().Register("ssh", NewListener)
}
type sshListener struct {
@ -99,7 +99,7 @@ func (l *sshListener) serveConn(conn net.Conn) {
start := time.Now()
l.logger.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
l.logger.WithFields(map[string]interface{}{
l.logger.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()

View File

@ -23,7 +23,7 @@ const (
)
func init() {
registry.RegisterListener("sshd", NewListener)
registry.ListenerRegistry().Register("sshd", NewListener)
}
type sshdListener struct {
@ -108,7 +108,7 @@ func (l *sshdListener) serveConn(conn net.Conn) {
start := time.Now()
l.logger.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
l.logger.WithFields(map[string]interface{}{
l.logger.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
}()

View File

@ -11,7 +11,7 @@ import (
)
func init() {
registry.RegisterListener("tap", NewListener)
registry.ListenerRegistry().Register("tap", NewListener)
}
type tapListener struct {

View File

@ -10,7 +10,7 @@ import (
)
func init() {
registry.RegisterListener("tcp", NewListener)
registry.ListenerRegistry().Register("tcp", NewListener)
}
type tcpListener struct {

View File

@ -11,7 +11,7 @@ import (
)
func init() {
registry.RegisterListener("tls", NewListener)
registry.ListenerRegistry().Register("tls", NewListener)
}
type tlsListener struct {

View File

@ -12,7 +12,7 @@ import (
)
func init() {
registry.RegisterListener("mtls", NewListener)
registry.ListenerRegistry().Register("mtls", NewListener)
}
type mtlsListener struct {

View File

@ -11,7 +11,7 @@ import (
)
func init() {
registry.RegisterListener("tun", NewListener)
registry.ListenerRegistry().Register("tun", NewListener)
}
type tunListener struct {

View File

@ -11,7 +11,7 @@ import (
)
func init() {
registry.RegisterListener("udp", NewListener)
registry.ListenerRegistry().Register("udp", NewListener)
}
type udpListener struct {

View File

@ -15,8 +15,8 @@ import (
)
func init() {
registry.RegisterListener("ws", NewListener)
registry.RegisterListener("wss", NewTLSListener)
registry.ListenerRegistry().Register("ws", NewListener)
registry.ListenerRegistry().Register("wss", NewTLSListener)
}
type wsListener struct {
@ -121,7 +121,7 @@ func (l *wsListener) Addr() net.Addr {
func (l *wsListener) upgrade(w http.ResponseWriter, r *http.Request) {
if l.logger.IsLevelEnabled(logger.DebugLevel) {
log := l.logger.WithFields(map[string]interface{}{
log := l.logger.WithFields(map[string]any{
"local": l.addr.String(),
"remote": r.RemoteAddr,
})

View File

@ -16,8 +16,8 @@ import (
)
func init() {
registry.RegisterListener("mws", NewListener)
registry.RegisterListener("mwss", NewTLSListener)
registry.ListenerRegistry().Register("mws", NewListener)
registry.ListenerRegistry().Register("mwss", NewTLSListener)
}
type mwsListener struct {
@ -126,7 +126,7 @@ func (l *mwsListener) Addr() net.Addr {
func (l *mwsListener) upgrade(w http.ResponseWriter, r *http.Request) {
if l.logger.IsLevelEnabled(logger.DebugLevel) {
log := l.logger.WithFields(map[string]interface{}{
log := l.logger.WithFields(map[string]any{
"local": l.addr.String(),
"remote": r.RemoteAddr,
})

View File

@ -61,60 +61,60 @@ func NewLogger(opts ...LoggerOption) Logger {
}
// WithFields adds new fields to log.
func (l *logger) WithFields(fields map[string]interface{}) Logger {
func (l *logger) WithFields(fields map[string]any) Logger {
return &logger{
logger: l.logger.WithFields(logrus.Fields(fields)),
}
}
// Debug logs a message at level Debug.
func (l *logger) Debug(args ...interface{}) {
func (l *logger) Debug(args ...any) {
l.log(logrus.DebugLevel, args...)
}
// Debugf logs a message at level Debug.
func (l *logger) Debugf(format string, args ...interface{}) {
func (l *logger) Debugf(format string, args ...any) {
l.logf(logrus.DebugLevel, format, args...)
}
// Info logs a message at level Info.
func (l *logger) Info(args ...interface{}) {
func (l *logger) Info(args ...any) {
l.log(logrus.InfoLevel, args...)
}
// Infof logs a message at level Info.
func (l *logger) Infof(format string, args ...interface{}) {
func (l *logger) Infof(format string, args ...any) {
l.logf(logrus.InfoLevel, format, args...)
}
// Warn logs a message at level Warn.
func (l *logger) Warn(args ...interface{}) {
func (l *logger) Warn(args ...any) {
l.log(logrus.WarnLevel, args...)
}
// Warnf logs a message at level Warn.
func (l *logger) Warnf(format string, args ...interface{}) {
func (l *logger) Warnf(format string, args ...any) {
l.logf(logrus.WarnLevel, format, args...)
}
// Error logs a message at level Error.
func (l *logger) Error(args ...interface{}) {
func (l *logger) Error(args ...any) {
l.log(logrus.ErrorLevel, args...)
}
// Errorf logs a message at level Error.
func (l *logger) Errorf(format string, args ...interface{}) {
func (l *logger) Errorf(format string, args ...any) {
l.logf(logrus.ErrorLevel, format, args...)
}
// Fatal logs a message at level Fatal then the process will exit with status set to 1.
func (l *logger) Fatal(args ...interface{}) {
func (l *logger) Fatal(args ...any) {
l.log(logrus.FatalLevel, args...)
l.logger.Logger.Exit(1)
}
// Fatalf logs a message at level Fatal then the process will exit with status set to 1.
func (l *logger) Fatalf(format string, args ...interface{}) {
func (l *logger) Fatalf(format string, args ...any) {
l.logf(logrus.FatalLevel, format, args...)
l.logger.Logger.Exit(1)
}
@ -128,7 +128,7 @@ func (l *logger) IsLevelEnabled(level LogLevel) bool {
return l.logger.Logger.IsLevelEnabled(lvl)
}
func (l *logger) log(level logrus.Level, args ...interface{}) {
func (l *logger) log(level logrus.Level, args ...any) {
lg := l.logger
if l.logger.Logger.IsLevelEnabled(logrus.DebugLevel) {
lg = lg.WithField("caller", l.caller(3))
@ -136,7 +136,7 @@ func (l *logger) log(level logrus.Level, args ...interface{}) {
lg.Log(level, args...)
}
func (l *logger) logf(level logrus.Level, format string, args ...interface{}) {
func (l *logger) logf(level logrus.Level, format string, args ...any) {
lg := l.logger
if l.logger.Logger.IsLevelEnabled(logrus.DebugLevel) {
lg = lg.WithField("caller", l.caller(3))

View File

@ -29,17 +29,17 @@ const (
)
type Logger interface {
WithFields(map[string]interface{}) Logger
Debug(args ...interface{})
Debugf(format string, args ...interface{})
Info(args ...interface{})
Infof(format string, args ...interface{})
Warn(args ...interface{})
Warnf(format string, args ...interface{})
Error(args ...interface{})
Errorf(format string, args ...interface{})
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
WithFields(map[string]any) Logger
Debug(args ...any)
Debugf(format string, args ...any)
Info(args ...any)
Infof(format string, args ...any)
Warn(args ...any)
Warnf(format string, args ...any)
Error(args ...any)
Errorf(format string, args ...any)
Fatal(args ...any)
Fatalf(format string, args ...any)
GetLevel() LogLevel
IsLevelEnabled(level LogLevel) bool
}

View File

@ -10,38 +10,38 @@ func Nop() Logger {
type nopLogger struct{}
func (l *nopLogger) WithFields(fields map[string]interface{}) Logger {
func (l *nopLogger) WithFields(fields map[string]any) Logger {
return l
}
func (l *nopLogger) Debug(args ...interface{}) {
func (l *nopLogger) Debug(args ...any) {
}
func (l *nopLogger) Debugf(format string, args ...interface{}) {
func (l *nopLogger) Debugf(format string, args ...any) {
}
func (l *nopLogger) Info(args ...interface{}) {
func (l *nopLogger) Info(args ...any) {
}
func (l *nopLogger) Infof(format string, args ...interface{}) {
func (l *nopLogger) Infof(format string, args ...any) {
}
func (l *nopLogger) Warn(args ...interface{}) {
func (l *nopLogger) Warn(args ...any) {
}
func (l *nopLogger) Warnf(format string, args ...interface{}) {
func (l *nopLogger) Warnf(format string, args ...any) {
}
func (l *nopLogger) Error(args ...interface{}) {
func (l *nopLogger) Error(args ...any) {
}
func (l *nopLogger) Errorf(format string, args ...interface{}) {
func (l *nopLogger) Errorf(format string, args ...any) {
}
func (l *nopLogger) Fatal(args ...interface{}) {
func (l *nopLogger) Fatal(args ...any) {
}
func (l *nopLogger) Fatalf(format string, args ...interface{}) {
func (l *nopLogger) Fatalf(format string, args ...any) {
}
func (l *nopLogger) GetLevel() LogLevel {

View File

@ -8,22 +8,22 @@ import (
type Metadata interface {
IsExists(key string) bool
Set(key string, value interface{})
Get(key string) interface{}
Set(key string, value any)
Get(key string) any
}
type MapMetadata map[string]interface{}
type MapMetadata map[string]any
func (m MapMetadata) IsExists(key string) bool {
_, ok := m[key]
return ok
}
func (m MapMetadata) Set(key string, value interface{}) {
func (m MapMetadata) Set(key string, value any) {
m[key] = value
}
func (m MapMetadata) Get(key string) interface{} {
func (m MapMetadata) Get(key string) any {
if m != nil {
return m[key]
}
@ -112,7 +112,7 @@ func GetStrings(md Metadata, key string) (ss []string) {
switch v := md.Get(key).(type) {
case []string:
ss = v
case []interface{}:
case []any:
for _, vv := range v {
if s, ok := vv.(string); ok {
ss = append(ss, s)
@ -122,12 +122,12 @@ func GetStrings(md Metadata, key string) (ss []string) {
return
}
func GetStringMap(md Metadata, key string) (m map[string]interface{}) {
func GetStringMap(md Metadata, key string) (m map[string]any) {
switch vv := md.Get(key).(type) {
case map[string]interface{}:
case map[string]any:
return vv
case map[interface{}]interface{}:
m = make(map[string]interface{})
case map[any]any:
m = make(map[string]any)
for k, v := range vv {
m[fmt.Sprintf("%v", k)] = v
}
@ -137,12 +137,12 @@ func GetStringMap(md Metadata, key string) (m map[string]interface{}) {
func GetStringMapString(md Metadata, key string) (m map[string]string) {
switch vv := md.Get(key).(type) {
case map[string]interface{}:
case map[string]any:
m = make(map[string]string)
for k, v := range vv {
m[k] = fmt.Sprintf("%v", v)
}
case map[interface{}]interface{}:
case map[any]any:
m = make(map[string]string)
for k, v := range vv {
m[fmt.Sprintf("%v", k)] = fmt.Sprintf("%v", v)

Some files were not shown because too many files have changed in this diff Show More