config_json.go 802 B

123456789101112131415161718192021222324252627282930313233
  1. // +build json
  2. package freedom
  3. import (
  4. "encoding/json"
  5. "errors"
  6. "strings"
  7. "github.com/v2ray/v2ray-core/proxy/internal"
  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 = DomainStrategyAsIs
  19. domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)
  20. if domainStrategy == "useip" {
  21. this.DomainStrategy = DomainStrategyUseIP
  22. }
  23. this.Timeout = jsonConfig.Timeout
  24. return nil
  25. }
  26. func init() {
  27. internal.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) })
  28. }