v2ray-core/transport/config_json.go

28 lines
579 B
Go
Raw Normal View History

2016-06-01 23:49:25 +00:00
// +build json
package transport
2016-06-11 11:51:02 +00:00
import (
"encoding/json"
2016-06-14 20:54:08 +00:00
"github.com/v2ray/v2ray-core/transport/internet/kcp"
"github.com/v2ray/v2ray-core/transport/internet/tcp"
2016-06-11 11:51:02 +00:00
)
2016-06-01 23:49:25 +00:00
func (this *Config) UnmarshalJSON(data []byte) error {
2016-06-02 18:52:52 +00:00
type JsonConfig struct {
2016-06-14 20:54:08 +00:00
TCPConfig *tcp.Config `json:"tcpSettings"`
2016-06-17 14:57:48 +00:00
KCPConfig kcp.Config `json:"kcpSettings"`
}
jsonConfig := &JsonConfig{
KCPConfig: kcp.DefaultConfig(),
2016-06-11 00:05:29 +00:00
}
2016-06-02 18:52:52 +00:00
if err := json.Unmarshal(data, jsonConfig); err != nil {
2016-06-01 23:49:25 +00:00
return err
}
2016-06-14 20:54:08 +00:00
this.tcpConfig = jsonConfig.TCPConfig
2016-06-17 14:57:48 +00:00
this.kcpConfig = jsonConfig.KCPConfig
2016-06-01 23:49:25 +00:00
return nil
}