mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
code optimization (#3625)
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/fatedier/frp/pkg/consts"
|
||||
"github.com/fatedier/frp/pkg/util/util"
|
||||
)
|
||||
|
||||
@@ -73,10 +72,18 @@ type VisitorConfigurer interface {
|
||||
GetBaseConfig() *VisitorBaseConfig
|
||||
}
|
||||
|
||||
var visitorConfigTypeMap = map[string]reflect.Type{
|
||||
consts.STCPProxy: reflect.TypeOf(STCPVisitorConfig{}),
|
||||
consts.XTCPProxy: reflect.TypeOf(XTCPVisitorConfig{}),
|
||||
consts.SUDPProxy: reflect.TypeOf(SUDPVisitorConfig{}),
|
||||
type VisitorType string
|
||||
|
||||
const (
|
||||
VisitorTypeSTCP VisitorType = "stcp"
|
||||
VisitorTypeXTCP VisitorType = "xtcp"
|
||||
VisitorTypeSUDP VisitorType = "sudp"
|
||||
)
|
||||
|
||||
var visitorConfigTypeMap = map[VisitorType]reflect.Type{
|
||||
VisitorTypeSTCP: reflect.TypeOf(STCPVisitorConfig{}),
|
||||
VisitorTypeXTCP: reflect.TypeOf(XTCPVisitorConfig{}),
|
||||
VisitorTypeSUDP: reflect.TypeOf(SUDPVisitorConfig{}),
|
||||
}
|
||||
|
||||
type TypedVisitorConfig struct {
|
||||
@@ -97,7 +104,7 @@ func (c *TypedVisitorConfig) UnmarshalJSON(b []byte) error {
|
||||
}
|
||||
|
||||
c.Type = typeStruct.Type
|
||||
configurer := NewVisitorConfigurerByType(typeStruct.Type)
|
||||
configurer := NewVisitorConfigurerByType(VisitorType(typeStruct.Type))
|
||||
if configurer == nil {
|
||||
return fmt.Errorf("unknown visitor type: %s", typeStruct.Type)
|
||||
}
|
||||
@@ -108,7 +115,7 @@ func (c *TypedVisitorConfig) UnmarshalJSON(b []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewVisitorConfigurerByType(t string) VisitorConfigurer {
|
||||
func NewVisitorConfigurerByType(t VisitorType) VisitorConfigurer {
|
||||
v, ok := visitorConfigTypeMap[t]
|
||||
if !ok {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user