1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-16 04:35:24 +00:00
v2fly/proxy/freedom/config_json.go

34 lines
789 B
Go
Raw Normal View History

// +build json
package freedom
import (
2016-05-22 20:30:21 +00:00
"encoding/json"
2016-06-11 20:52:37 +00:00
"errors"
2016-05-24 20:41:51 +00:00
"strings"
2016-05-22 20:30:21 +00:00
2016-08-20 18:55:45 +00:00
"v2ray.com/core/proxy/registry"
)
2016-05-22 20:30:21 +00:00
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
DomainStrategy string `json:"domainStrategy"`
2016-06-02 21:18:44 +00:00
Timeout uint32 `json:"timeout"`
2016-05-22 20:30:21 +00:00
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
2016-06-11 20:52:37 +00:00
return errors.New("Freedom: Failed to parse config: " + err.Error())
2016-05-22 20:30:21 +00:00
}
this.DomainStrategy = DomainStrategyAsIs
2016-05-24 20:41:51 +00:00
domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)
if domainStrategy == "useip" {
2016-05-22 20:30:21 +00:00
this.DomainStrategy = DomainStrategyUseIP
}
2016-06-02 21:18:44 +00:00
this.Timeout = jsonConfig.Timeout
2016-05-22 20:30:21 +00:00
return nil
}
func init() {
registry.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) })
}