diff --git a/config/json/connection.go b/config/json/connection.go new file mode 100644 index 000000000..96606006e --- /dev/null +++ b/config/json/connection.go @@ -0,0 +1,32 @@ +package json + +import ( + "encoding/json" + + "github.com/v2ray/v2ray-core/common/log" + "github.com/v2ray/v2ray-core/config" +) + +type ConnectionConfig struct { + ProtocolString string `json:"protocol"` + SettingsMessage json.RawMessage `json:"settings"` + Type config.Type `json:"-"` +} + +func (c *ConnectionConfig) Protocol() string { + return c.ProtocolString +} + +func (c *ConnectionConfig) Settings() interface{} { + creator, found := configCache[getConfigKey(c.Protocol(), c.Type)] + if !found { + panic("Unknown protocol " + c.Protocol()) + } + configObj := creator() + err := json.Unmarshal(c.SettingsMessage, configObj) + if err != nil { + log.Error("Unable to parse connection config: %v", err) + panic("Failed to parse connection config.") + } + return configObj +} diff --git a/config/json/json.go b/config/json/json.go index 3cf95d407..18018a559 100644 --- a/config/json/json.go +++ b/config/json/json.go @@ -9,38 +9,6 @@ import ( "github.com/v2ray/v2ray-core/config" ) -type ConnectionConfig struct { - ProtocolString string `json:"protocol"` - SettingsMessage json.RawMessage `json:"settings"` - Type config.Type `json:"-"` -} - -func (config *ConnectionConfig) Protocol() string { - return config.ProtocolString -} - -func (config *ConnectionConfig) Settings() interface{} { - creator, found := configCache[getConfigKey(config.Protocol(), config.Type)] - if !found { - panic("Unknown protocol " + config.Protocol()) - } - configObj := creator() - err := json.Unmarshal(config.SettingsMessage, configObj) - if err != nil { - log.Error("Unable to parse connection config: %v", err) - panic("Failed to parse connection config.") - } - return configObj -} - -type LogConfig struct { - AccessLogValue string `json:"access"` -} - -func (config *LogConfig) AccessLog() string { - return config.AccessLogValue -} - // Config is the config for Point server. type Config struct { PortValue uint16 `json:"port"` // Port of this Point server. diff --git a/config/json/log.go b/config/json/log.go new file mode 100644 index 000000000..05a832636 --- /dev/null +++ b/config/json/log.go @@ -0,0 +1,9 @@ +package json + +type LogConfig struct { + AccessLogValue string `json:"access"` +} + +func (config *LogConfig) AccessLog() string { + return config.AccessLogValue +}