v2ray-core/transport/config_json.go

39 lines
793 B
Go
Raw Normal View History

2016-06-01 23:49:25 +00:00
// +build json
package transport
import (
"encoding/json"
"strings"
)
func (this *Config) UnmarshalJSON(data []byte) error {
type TypeConfig struct {
StreamType string `json:"streamType"`
Settings json.RawMessage `json:"settings"`
}
type JsonTCPConfig struct {
ConnectionReuse bool `json:"connectionReuse"`
}
typeConfig := new(TypeConfig)
if err := json.Unmarshal(data, typeConfig); err != nil {
return err
}
2016-06-02 00:20:53 +00:00
this.StreamType = StreamTypeTCP
2016-06-01 23:49:25 +00:00
streamType := strings.ToLower(typeConfig.StreamType)
if streamType == "tcp" {
jsonTCPConfig := new(JsonTCPConfig)
2016-06-02 00:20:53 +00:00
if err := json.Unmarshal(typeConfig.Settings, jsonTCPConfig); err != nil {
2016-06-01 23:49:25 +00:00
return err
}
this.TCPConfig = &TCPConfig{
ConnectionReuse: jsonTCPConfig.ConnectionReuse,
}
}
return nil
}