1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00
v2fly/transport/config_json.go
2016-06-02 01:49:25 +02:00

37 lines
744 B
Go

// +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
}
streamType := strings.ToLower(typeConfig.StreamType)
if streamType == "tcp" {
jsonTCPConfig := new(JsonTCPConfig)
if err := json.Unmarshal(data, jsonTCPConfig); err != nil {
return err
}
this.TCPConfig = &TCPConfig{
ConnectionReuse: jsonTCPConfig.ConnectionReuse,
}
}
return nil
}