config_json.go 670 B

12345678910111213141516171819202122232425262728293031
  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. )
  8. func (this *Config) UnmarshalJSON(data []byte) error {
  9. type RawOutbound struct {
  10. Receivers []*Receiver `json:"vnext"`
  11. }
  12. rawOutbound := &RawOutbound{}
  13. err := json.Unmarshal(data, rawOutbound)
  14. if err != nil {
  15. return err
  16. }
  17. if len(rawOutbound.Receivers) == 0 {
  18. log.Error("VMess: 0 VMess receiver configured.")
  19. return internal.ErrorBadConfiguration
  20. }
  21. this.Receivers = rawOutbound.Receivers
  22. return nil
  23. }
  24. func init() {
  25. internal.RegisterOutboundConfig("vmess", func() interface{} { return new(Config) })
  26. }