v2ray-core/proxy/http/config_json.go

29 lines
588 B
Go
Raw Normal View History

// +build json
package http
import (
2016-01-26 10:28:09 +00:00
"encoding/json"
2016-06-11 20:52:37 +00:00
"errors"
2016-01-26 10:28:09 +00:00
2016-08-20 18:55:45 +00:00
"v2ray.com/core/proxy/registry"
)
2016-05-29 14:46:31 +00:00
// UnmarshalJSON implements json.Unmarshaler
2016-08-25 19:55:49 +00:00
func (this *ServerConfig) UnmarshalJSON(data []byte) error {
2016-01-26 10:28:09 +00:00
type JsonConfig struct {
2016-08-25 19:55:49 +00:00
Timeout uint32 `json:"timeout"`
2016-01-26 10:28:09 +00:00
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
2016-06-11 20:52:37 +00:00
return errors.New("HTTP: Failed to parse config: " + err.Error())
2016-01-26 10:28:09 +00:00
}
2016-07-10 13:34:14 +00:00
this.Timeout = jsonConfig.Timeout
2016-01-26 10:28:09 +00:00
return nil
}
func init() {
2016-08-25 19:55:49 +00:00
registry.RegisterInboundConfig("http", func() interface{} { return new(ServerConfig) })
}