1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-19 10:26:10 -04:00
v2fly/shell/point/json/connection.go

37 lines
1011 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"
2015-10-30 17:42:24 -04:00
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
proxyjson "github.com/v2ray/v2ray-core/proxy/common/config/json"
2015-10-29 18:41:37 -04:00
)
type ConnectionConfig struct {
2015-10-30 17:42:24 -04:00
ProtocolString string `json:"protocol"`
SettingsMessage json.RawMessage `json:"settings"`
Type proxyconfig.Type `json:"-"`
2015-10-29 18:41:37 -04:00
}
func (c *ConnectionConfig) Protocol() string {
return c.ProtocolString
}
func (c *ConnectionConfig) Settings() interface{} {
2015-10-31 17:22:43 -04:00
return loadConnectionConfig(c.SettingsMessage, c.Protocol(), c.Type)
}
func loadConnectionConfig(message json.RawMessage, protocol string, cType proxyconfig.Type) interface{} {
configObj := proxyjson.CreateConfig(protocol, cType)
2015-10-30 17:42:24 -04:00
if configObj == nil {
2015-10-31 17:22:43 -04:00
panic("Unknown protocol " + protocol)
2015-10-29 18:41:37 -04:00
}
2015-10-31 17:22:43 -04:00
err := json.Unmarshal(message, configObj)
2015-10-29 18:41:37 -04:00
if err != nil {
log.Error("Unable to parse connection config: %v", err)
panic("Failed to parse connection config.")
}
return configObj
}