mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
Split json config files
This commit is contained in:
parent
6e8425b23a
commit
ce07ea9769
32
config/json/connection.go
Normal file
32
config/json/connection.go
Normal 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
|
||||||
|
}
|
@ -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
9
config/json/log.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package json
|
||||||
|
|
||||||
|
type LogConfig struct {
|
||||||
|
AccessLogValue string `json:"access"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config *LogConfig) AccessLog() string {
|
||||||
|
return config.AccessLogValue
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user