config_json.go 641 B

12345678910111213141516171819202122232425262728
  1. // +build json
  2. package router
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/common/log"
  6. )
  7. func (this *Config) UnmarshalJSON(data []byte) error {
  8. type JsonConfig struct {
  9. Strategy string `json:"strategy"`
  10. Settings json.RawMessage `json:"settings"`
  11. }
  12. jsonConfig := new(JsonConfig)
  13. if err := json.Unmarshal(data, jsonConfig); err != nil {
  14. return err
  15. }
  16. settings, err := CreateRouterConfig(jsonConfig.Strategy, []byte(jsonConfig.Settings))
  17. if err != nil {
  18. log.Error("Router: Failed to load router settings: ", err)
  19. return err
  20. }
  21. this.Strategy = jsonConfig.Strategy
  22. this.Settings = settings
  23. return nil
  24. }