config_json.go 386 B

12345678910111213141516171819
  1. // +build json
  2. package transport
  3. import "encoding/json"
  4. func (this *Config) UnmarshalJSON(data []byte) error {
  5. type JsonConfig struct {
  6. ConnectionReuse bool `json:"connectionReuse"`
  7. }
  8. jsonConfig := &JsonConfig{
  9. ConnectionReuse: true,
  10. }
  11. if err := json.Unmarshal(data, jsonConfig); err != nil {
  12. return err
  13. }
  14. this.ConnectionReuse = jsonConfig.ConnectionReuse
  15. return nil
  16. }