config_json.go 586 B

12345678910111213141516171819202122232425262728
  1. // +build json
  2. package http
  3. import (
  4. "encoding/json"
  5. "errors"
  6. "github.com/v2ray/v2ray-core/proxy/registry"
  7. )
  8. // UnmarshalJSON implements json.Unmarshaler
  9. func (this *Config) UnmarshalJSON(data []byte) error {
  10. type JsonConfig struct {
  11. Timeout int `json:"timeout"`
  12. }
  13. jsonConfig := new(JsonConfig)
  14. if err := json.Unmarshal(data, jsonConfig); err != nil {
  15. return errors.New("HTTP: Failed to parse config: " + err.Error())
  16. }
  17. this.Timeout = jsonConfig.Timeout
  18. return nil
  19. }
  20. func init() {
  21. registry.RegisterInboundConfig("http", func() interface{} { return new(Config) })
  22. }