config_json.go 448 B

12345678910111213141516171819202122
  1. // +build json
  2. package http
  3. import (
  4. "encoding/json"
  5. "errors"
  6. )
  7. // UnmarshalJSON implements json.Unmarshaler
  8. func (this *ServerConfig) UnmarshalJSON(data []byte) error {
  9. type JsonConfig struct {
  10. Timeout uint32 `json:"timeout"`
  11. }
  12. jsonConfig := new(JsonConfig)
  13. if err := json.Unmarshal(data, jsonConfig); err != nil {
  14. return errors.New("HTTP: Failed to parse config: " + err.Error())
  15. }
  16. this.Timeout = jsonConfig.Timeout
  17. return nil
  18. }