config_json.go 734 B

1234567891011121314151617181920212223242526272829303132
  1. // +build json
  2. package freedom
  3. import (
  4. "encoding/json"
  5. "strings"
  6. "github.com/v2ray/v2ray-core/proxy/internal"
  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. internal.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) })
  27. }