config_json.go 900 B

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