config_json.go 663 B

12345678910111213141516171819202122232425262728
  1. // +build json
  2. package transport
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/transport/hub/kcpv"
  6. )
  7. func (this *Config) UnmarshalJSON(data []byte) error {
  8. type JsonConfig struct {
  9. ConnectionReuse bool `json:"connectionReuse"`
  10. EnableKcp bool `json:"EnableKCP,omitempty"`
  11. KcpConfig *kcpv.Config `json:"KcpConfig,omitempty"`
  12. }
  13. jsonConfig := &JsonConfig{
  14. ConnectionReuse: true,
  15. EnableKcp: false,
  16. }
  17. if err := json.Unmarshal(data, jsonConfig); err != nil {
  18. return err
  19. }
  20. this.ConnectionReuse = jsonConfig.ConnectionReuse
  21. this.enableKcp = jsonConfig.EnableKcp
  22. this.kcpConfig = kcpConfig
  23. return nil
  24. }