config_json.go 549 B

12345678910111213141516171819202122232425
  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. }
  11. jsonConfig := &JsonConfig{
  12. ConnectionReuse: true,
  13. Path: "",
  14. Pto: "",
  15. }
  16. if err := json.Unmarshal(data, jsonConfig); err != nil {
  17. return err
  18. }
  19. this.ConnectionReuse = jsonConfig.ConnectionReuse
  20. this.Path = jsonConfig.Path
  21. this.Pto = jsonConfig.Pto
  22. return nil
  23. }