1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00
v2fly/proxy/freedom/config_json.go
Darien Raymond bbca180dba
try protobuf
2016-08-25 21:55:49 +02:00

34 lines
807 B
Go

// +build json
package freedom
import (
"encoding/json"
"errors"
"strings"
"v2ray.com/core/proxy/registry"
)
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
DomainStrategy string `json:"domainStrategy"`
Timeout uint32 `json:"timeout"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return errors.New("Freedom: Failed to parse config: " + err.Error())
}
this.DomainStrategy = Config_AS_IS
domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)
if domainStrategy == "useip" || domainStrategy == "use_ip" {
this.DomainStrategy = Config_USE_IP
}
this.Timeout = jsonConfig.Timeout
return nil
}
func init() {
registry.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) })
}