1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-12 15:27:16 -05:00
v2fly/config/json/connection.go

33 lines
779 B
Go
Raw Normal View History

2015-10-29 18:41:37 -04:00
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
}