config_json.go 740 B

1234567891011121314151617181920212223242526272829303132
  1. // +build json
  2. package outbound
  3. import (
  4. "encoding/json"
  5. "errors"
  6. "github.com/v2ray/v2ray-core/common/log"
  7. "github.com/v2ray/v2ray-core/proxy/internal"
  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 errors.New("VMessOut: Failed to parse config: " + err.Error())
  17. }
  18. if len(rawOutbound.Receivers) == 0 {
  19. log.Error("VMessOut: 0 VMess receiver configured.")
  20. return internal.ErrBadConfiguration
  21. }
  22. this.Receivers = rawOutbound.Receivers
  23. return nil
  24. }
  25. func init() {
  26. internal.RegisterOutboundConfig("vmess", func() interface{} { return new(Config) })
  27. }