config_json.go 857 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // +build json
  2. package freedom
  3. import (
  4. "encoding/json"
  5. "strings"
  6. "github.com/v2ray/v2ray-core/proxy/internal/config"
  7. )
  8. func (this *Config) UnmarshalJSON(data []byte) error {
  9. type JsonConfig struct {
  10. DomainStrategy string `json:"domainStrategy"`
  11. Timeout uint32 `json:"timeout"`
  12. }
  13. jsonConfig := new(JsonConfig)
  14. if err := json.Unmarshal(data, jsonConfig); err != nil {
  15. return err
  16. }
  17. this.DomainStrategy = DomainStrategyAsIs
  18. domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)
  19. if domainStrategy == "useip" {
  20. this.DomainStrategy = DomainStrategyUseIP
  21. }
  22. this.Timeout = jsonConfig.Timeout
  23. return nil
  24. }
  25. func init() {
  26. config.RegisterOutboundConfig("freedom",
  27. func(data []byte) (interface{}, error) {
  28. c := new(Config)
  29. if err := json.Unmarshal(data, c); err != nil {
  30. return nil, err
  31. }
  32. return c, nil
  33. })
  34. }