config_json.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // +build json
  2. package inbound
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/proxy/internal/config"
  6. "github.com/v2ray/v2ray-core/proxy/vmess"
  7. )
  8. func (this *DetourConfig) UnmarshalJSON(data []byte) error {
  9. type JsonDetourConfig struct {
  10. ToTag string `json:"to"`
  11. }
  12. jsonConfig := new(JsonDetourConfig)
  13. if err := json.Unmarshal(data, jsonConfig); err != nil {
  14. return err
  15. }
  16. this.ToTag = jsonConfig.ToTag
  17. return nil
  18. }
  19. func (this *FeaturesConfig) UnmarshalJSON(data []byte) error {
  20. type JsonFeaturesConfig struct {
  21. Detour *DetourConfig `json:"detour"`
  22. }
  23. jsonConfig := new(JsonFeaturesConfig)
  24. if err := json.Unmarshal(data, jsonConfig); err != nil {
  25. return err
  26. }
  27. this.Detour = jsonConfig.Detour
  28. return nil
  29. }
  30. func (this *Config) UnmarshalJSON(data []byte) error {
  31. type JsonConfig struct {
  32. Users []*vmess.User `json:"clients"`
  33. Features *FeaturesConfig `json:"features"`
  34. }
  35. jsonConfig := new(JsonConfig)
  36. if err := json.Unmarshal(data, jsonConfig); err != nil {
  37. return err
  38. }
  39. this.AllowedUsers = jsonConfig.Users
  40. this.Features = jsonConfig.Features
  41. return nil
  42. }
  43. func init() {
  44. config.RegisterInboundConfig("vmess",
  45. func(data []byte) (interface{}, error) {
  46. config := new(Config)
  47. err := json.Unmarshal(data, config)
  48. return config, err
  49. })
  50. }