config_json.go 712 B

1234567891011121314151617181920212223242526272829
  1. // +build json
  2. package transport
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/transport/internet/kcp"
  6. "github.com/v2ray/v2ray-core/transport/internet/tcp"
  7. "github.com/v2ray/v2ray-core/transport/internet/ws"
  8. )
  9. func (this *Config) UnmarshalJSON(data []byte) error {
  10. type JsonConfig struct {
  11. TCPConfig *tcp.Config `json:"tcpSettings"`
  12. KCPConfig kcp.Config `json:"kcpSettings"`
  13. WSConfig *ws.Config `json:"wsSettings"`
  14. }
  15. jsonConfig := &JsonConfig{
  16. KCPConfig: kcp.DefaultConfig(),
  17. }
  18. if err := json.Unmarshal(data, jsonConfig); err != nil {
  19. return err
  20. }
  21. this.tcpConfig = jsonConfig.TCPConfig
  22. this.kcpConfig = jsonConfig.KCPConfig
  23. this.wsConfig = jsonConfig.WSConfig
  24. return nil
  25. }