config_json.go 781 B

12345678910111213141516171819202122232425262728293031323334353637
  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. }
  12. jsonConfig := new(JsonConfig)
  13. if err := json.Unmarshal(data, jsonConfig); err != nil {
  14. return err
  15. }
  16. this.DomainStrategy = DomainStrategyAsIs
  17. domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)
  18. if domainStrategy == "useip" {
  19. this.DomainStrategy = DomainStrategyUseIP
  20. }
  21. return nil
  22. }
  23. func init() {
  24. config.RegisterOutboundConfig("freedom",
  25. func(data []byte) (interface{}, error) {
  26. c := new(Config)
  27. if err := json.Unmarshal(data, c); err != nil {
  28. return nil, err
  29. }
  30. return c, nil
  31. })
  32. }