1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-28 10:15:23 +00:00
v2fly/proxy/freedom/config_json.go
2016-08-17 23:30:15 +02:00

34 lines
802 B
Go

// +build json
package freedom
import (
"encoding/json"
"errors"
"strings"
"github.com/v2ray/v2ray-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 = DomainStrategyAsIs
domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)
if domainStrategy == "useip" {
this.DomainStrategy = DomainStrategyUseIP
}
this.Timeout = jsonConfig.Timeout
return nil
}
func init() {
registry.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) })
}