config_json.go 807 B

123456789101112131415161718192021222324252627282930313233
  1. // +build json
  2. package freedom
  3. import (
  4. "encoding/json"
  5. "errors"
  6. "strings"
  7. "v2ray.com/core/proxy/registry"
  8. )
  9. func (this *Config) UnmarshalJSON(data []byte) error {
  10. type JsonConfig struct {
  11. DomainStrategy string `json:"domainStrategy"`
  12. Timeout uint32 `json:"timeout"`
  13. }
  14. jsonConfig := new(JsonConfig)
  15. if err := json.Unmarshal(data, jsonConfig); err != nil {
  16. return errors.New("Freedom: Failed to parse config: " + err.Error())
  17. }
  18. this.DomainStrategy = Config_AS_IS
  19. domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)
  20. if domainStrategy == "useip" || domainStrategy == "use_ip" {
  21. this.DomainStrategy = Config_USE_IP
  22. }
  23. this.Timeout = jsonConfig.Timeout
  24. return nil
  25. }
  26. func init() {
  27. registry.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) })
  28. }