config_json.go 890 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // +build json
  2. package outbound
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/common/log"
  6. "github.com/v2ray/v2ray-core/proxy/internal"
  7. proxyconfig "github.com/v2ray/v2ray-core/proxy/internal/config"
  8. )
  9. func (this *Config) UnmarshalJSON(data []byte) error {
  10. type RawOutbound struct {
  11. Receivers []*Receiver `json:"vnext"`
  12. }
  13. rawOutbound := &RawOutbound{}
  14. err := json.Unmarshal(data, rawOutbound)
  15. if err != nil {
  16. return err
  17. }
  18. if len(rawOutbound.Receivers) == 0 {
  19. log.Error("VMess: 0 VMess receiver configured.")
  20. return internal.ErrorBadConfiguration
  21. }
  22. this.Receivers = rawOutbound.Receivers
  23. return nil
  24. }
  25. func init() {
  26. proxyconfig.RegisterOutboundConnectionConfig("vmess",
  27. func(data []byte) (interface{}, error) {
  28. rawConfig := new(Config)
  29. if err := json.Unmarshal(data, rawConfig); err != nil {
  30. return nil, err
  31. }
  32. return rawConfig, nil
  33. })
  34. }