config_json.go 461 B

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