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:
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/fatedier/frp/pkg/config/types"
|
||||
"github.com/fatedier/frp/pkg/consts"
|
||||
"github.com/fatedier/frp/pkg/msg"
|
||||
"github.com/fatedier/frp/pkg/util/util"
|
||||
)
|
||||
@@ -174,7 +173,7 @@ func (c *TypedProxyConfig) UnmarshalJSON(b []byte) error {
|
||||
}
|
||||
|
||||
c.Type = typeStruct.Type
|
||||
configurer := NewProxyConfigurerByType(typeStruct.Type)
|
||||
configurer := NewProxyConfigurerByType(ProxyType(typeStruct.Type))
|
||||
if configurer == nil {
|
||||
return fmt.Errorf("unknown proxy type: %s", typeStruct.Type)
|
||||
}
|
||||
@@ -196,18 +195,31 @@ type ProxyConfigurer interface {
|
||||
UnmarshalFromMsg(*msg.NewProxy)
|
||||
}
|
||||
|
||||
var proxyConfigTypeMap = map[string]reflect.Type{
|
||||
consts.TCPProxy: reflect.TypeOf(TCPProxyConfig{}),
|
||||
consts.UDPProxy: reflect.TypeOf(UDPProxyConfig{}),
|
||||
consts.HTTPProxy: reflect.TypeOf(HTTPProxyConfig{}),
|
||||
consts.HTTPSProxy: reflect.TypeOf(HTTPSProxyConfig{}),
|
||||
consts.TCPMuxProxy: reflect.TypeOf(TCPMuxProxyConfig{}),
|
||||
consts.STCPProxy: reflect.TypeOf(STCPProxyConfig{}),
|
||||
consts.XTCPProxy: reflect.TypeOf(XTCPProxyConfig{}),
|
||||
consts.SUDPProxy: reflect.TypeOf(SUDPProxyConfig{}),
|
||||
type ProxyType string
|
||||
|
||||
const (
|
||||
ProxyTypeTCP ProxyType = "tcp"
|
||||
ProxyTypeUDP ProxyType = "udp"
|
||||
ProxyTypeTCPMUX ProxyType = "tcpmux"
|
||||
ProxyTypeHTTP ProxyType = "http"
|
||||
ProxyTypeHTTPS ProxyType = "https"
|
||||
ProxyTypeSTCP ProxyType = "stcp"
|
||||
ProxyTypeXTCP ProxyType = "xtcp"
|
||||
ProxyTypeSUDP ProxyType = "sudp"
|
||||
)
|
||||
|
||||
var proxyConfigTypeMap = map[ProxyType]reflect.Type{
|
||||
ProxyTypeTCP: reflect.TypeOf(TCPProxyConfig{}),
|
||||
ProxyTypeUDP: reflect.TypeOf(UDPProxyConfig{}),
|
||||
ProxyTypeHTTP: reflect.TypeOf(HTTPProxyConfig{}),
|
||||
ProxyTypeHTTPS: reflect.TypeOf(HTTPSProxyConfig{}),
|
||||
ProxyTypeTCPMUX: reflect.TypeOf(TCPMuxProxyConfig{}),
|
||||
ProxyTypeSTCP: reflect.TypeOf(STCPProxyConfig{}),
|
||||
ProxyTypeXTCP: reflect.TypeOf(XTCPProxyConfig{}),
|
||||
ProxyTypeSUDP: reflect.TypeOf(SUDPProxyConfig{}),
|
||||
}
|
||||
|
||||
func NewProxyConfigurerByType(proxyType string) ProxyConfigurer {
|
||||
func NewProxyConfigurerByType(proxyType ProxyType) ProxyConfigurer {
|
||||
v, ok := proxyConfigTypeMap[proxyType]
|
||||
if !ok {
|
||||
return nil
|
||||
@@ -316,6 +328,12 @@ func (c *HTTPSProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) {
|
||||
c.SubDomain = m.SubDomain
|
||||
}
|
||||
|
||||
type TCPMultiplexerType string
|
||||
|
||||
const (
|
||||
TCPMultiplexerHTTPConnect TCPMultiplexerType = "httpconnect"
|
||||
)
|
||||
|
||||
var _ ProxyConfigurer = &TCPMuxProxyConfig{}
|
||||
|
||||
type TCPMuxProxyConfig struct {
|
||||
|
||||
Reference in New Issue
Block a user