config_json.go 826 B

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