1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-16 00:48:14 -04:00
v2fly/proxy/freedom/config_json.go

40 lines
857 B
Go
Raw Normal View History

// +build json
package freedom
import (
2016-05-22 16:30:21 -04:00
"encoding/json"
2016-05-24 16:41:51 -04:00
"strings"
2016-05-22 16:30:21 -04:00
"github.com/v2ray/v2ray-core/proxy/internal/config"
)
2016-05-22 16:30:21 -04:00
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
DomainStrategy string `json:"domainStrategy"`
2016-06-02 17:18:44 -04:00
Timeout uint32 `json:"timeout"`
2016-05-22 16:30:21 -04:00
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.DomainStrategy = DomainStrategyAsIs
2016-05-24 16:41:51 -04:00
domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)
if domainStrategy == "useip" {
2016-05-22 16:30:21 -04:00
this.DomainStrategy = DomainStrategyUseIP
}
2016-06-02 17:18:44 -04:00
this.Timeout = jsonConfig.Timeout
2016-05-22 16:30:21 -04:00
return nil
}
func init() {
config.RegisterOutboundConfig("freedom",
func(data []byte) (interface{}, error) {
2016-05-22 16:30:21 -04:00
c := new(Config)
if err := json.Unmarshal(data, c); err != nil {
return nil, err
}
return c, nil
})
}