1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

Split json config files

This commit is contained in:
V2Ray 2015-10-29 23:41:37 +01:00
parent 6e8425b23a
commit ce07ea9769
3 changed files with 41 additions and 32 deletions

32
config/json/connection.go Normal file
View File

@ -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
}

View File

@ -9,38 +9,6 @@ import (
"github.com/v2ray/v2ray-core/config" "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. // Config is the config for Point server.
type Config struct { type Config struct {
PortValue uint16 `json:"port"` // Port of this Point server. PortValue uint16 `json:"port"` // Port of this Point server.

9
config/json/log.go Normal file
View File

@ -0,0 +1,9 @@
package json
type LogConfig struct {
AccessLogValue string `json:"access"`
}
func (config *LogConfig) AccessLog() string {
return config.AccessLogValue
}