config_json.go 545 B

12345678910111213141516171819202122232425
  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. )
  8. func (this *Config) UnmarshalJSON(data []byte) error {
  9. type JsonConfig struct {
  10. TCPConfig *tcp.Config `json:"tcpSettings"`
  11. KCPCOnfig *kcp.Config `json:"kcpSettings"`
  12. }
  13. jsonConfig := new(JsonConfig)
  14. if err := json.Unmarshal(data, jsonConfig); err != nil {
  15. return err
  16. }
  17. this.tcpConfig = jsonConfig.TCPConfig
  18. this.kcpConfig = jsonConfig.KCPCOnfig
  19. return nil
  20. }