config_json.go 736 B

123456789101112131415161718192021222324252627282930
  1. package ws
  2. import (
  3. "encoding/json"
  4. )
  5. func (this *Config) UnmarshalJSON(data []byte) error {
  6. type JsonConfig struct {
  7. ConnectionReuse bool `json:"connectionReuse"`
  8. Path string `json:"Path"`
  9. Pto string `json:"Pto"`
  10. Cert string `json:"Cert"`
  11. PrivKey string `json:"PrivKey"`
  12. }
  13. jsonConfig := &JsonConfig{
  14. ConnectionReuse: true,
  15. Path: "",
  16. Pto: "",
  17. }
  18. if err := json.Unmarshal(data, jsonConfig); err != nil {
  19. return err
  20. }
  21. this.ConnectionReuse = jsonConfig.ConnectionReuse
  22. this.Path = jsonConfig.Path
  23. this.Pto = jsonConfig.Pto
  24. this.PrivKey = jsonConfig.PrivKey
  25. this.Cert = jsonConfig.Cert
  26. this.DeveloperInsecureSkipVerify = false
  27. return nil
  28. }