config_json.go 694 B

1234567891011121314151617181920212223242526272829
  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. return nil
  27. }