config_json.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // +build json
  2. package dokodemo
  3. import (
  4. "encoding/json"
  5. "errors"
  6. v2net "github.com/v2ray/v2ray-core/common/net"
  7. "github.com/v2ray/v2ray-core/proxy/internal"
  8. )
  9. func (this *Config) UnmarshalJSON(data []byte) error {
  10. type DokodemoConfig struct {
  11. Host *v2net.AddressJson `json:"address"`
  12. PortValue v2net.Port `json:"port"`
  13. NetworkList *v2net.NetworkList `json:"network"`
  14. TimeoutValue int `json:"timeout"`
  15. Redirect bool `json:"followRedirect"`
  16. }
  17. rawConfig := new(DokodemoConfig)
  18. if err := json.Unmarshal(data, rawConfig); err != nil {
  19. return errors.New("Dokodemo: Failed to parse config: " + err.Error())
  20. }
  21. if rawConfig.Host != nil {
  22. this.Address = rawConfig.Host.Address
  23. }
  24. this.Port = rawConfig.PortValue
  25. this.Network = rawConfig.NetworkList
  26. this.Timeout = rawConfig.TimeoutValue
  27. this.FollowRedirect = rawConfig.Redirect
  28. return nil
  29. }
  30. func init() {
  31. internal.RegisterInboundConfig("dokodemo-door", func() interface{} { return new(Config) })
  32. }