json.go 550 B

1234567891011121314151617181920212223242526
  1. package json
  2. import (
  3. "encoding/json"
  4. "github.com/v2ray/v2ray-core/common/log"
  5. )
  6. type RouterConfig struct {
  7. StrategyValue string `json:"strategy"`
  8. SettingsValue json.RawMessage `json:"settings"`
  9. }
  10. func (this *RouterConfig) Strategy() string {
  11. return this.StrategyValue
  12. }
  13. func (this *RouterConfig) Settings() interface{} {
  14. settings := CreateRouterConfig(this.Strategy())
  15. err := json.Unmarshal(this.SettingsValue, settings)
  16. if err != nil {
  17. log.Error("Failed to load router settings: %v", err)
  18. return nil
  19. }
  20. return settings
  21. }