1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/tools/conf/blackhole.go

52 lines
1.1 KiB
Go
Raw Normal View History

2016-10-17 08:35:13 -04:00
package conf
import (
"encoding/json"
2016-12-21 15:43:00 -05:00
2016-12-15 05:51:09 -05:00
"v2ray.com/core/common/serial"
2016-10-17 08:35:13 -04:00
"v2ray.com/core/proxy/blackhole"
)
type NoneResponse struct{}
2016-12-15 05:51:09 -05:00
func (*NoneResponse) Build() (*serial.TypedMessage, error) {
return serial.ToTypedMessage(new(blackhole.NoneResponse)), nil
2016-10-17 08:35:13 -04:00
}
type HttpResponse struct{}
2016-12-15 05:51:09 -05:00
func (*HttpResponse) Build() (*serial.TypedMessage, error) {
return serial.ToTypedMessage(new(blackhole.HTTPResponse)), nil
2016-10-17 08:35:13 -04:00
}
type BlackholeConfig struct {
Response json.RawMessage `json:"response"`
}
2016-12-15 05:51:09 -05:00
func (v *BlackholeConfig) Build() (*serial.TypedMessage, error) {
2016-10-17 08:35:13 -04:00
config := new(blackhole.Config)
2016-11-27 15:39:09 -05:00
if v.Response != nil {
response, _, err := configLoader.Load(v.Response)
2016-10-17 08:35:13 -04:00
if err != nil {
2017-04-08 19:43:25 -04:00
return nil, newError("Config: Failed to parse Blackhole response config.").Base(err)
2016-10-17 08:35:13 -04:00
}
responseSettings, err := response.(Buildable).Build()
if err != nil {
return nil, err
}
config.Response = responseSettings
}
2016-12-15 05:51:09 -05:00
return serial.ToTypedMessage(config), nil
2016-10-17 08:35:13 -04:00
}
var (
configLoader = NewJSONConfigLoader(
ConfigCreatorCache{
"none": func() interface{} { return new(NoneResponse) },
"http": func() interface{} { return new(HttpResponse) },
},
"type",
"")
)