github.com/imannamdari/v2ray-core/v5@v5.0.5/infra/conf/v4/blackhole.go (about) 1 package v4 2 3 import ( 4 "encoding/json" 5 6 "github.com/golang/protobuf/proto" 7 8 "github.com/imannamdari/v2ray-core/v5/common/serial" 9 "github.com/imannamdari/v2ray-core/v5/infra/conf/cfgcommon" 10 "github.com/imannamdari/v2ray-core/v5/infra/conf/cfgcommon/loader" 11 "github.com/imannamdari/v2ray-core/v5/proxy/blackhole" 12 ) 13 14 type NoneResponse struct{} 15 16 func (*NoneResponse) Build() (proto.Message, error) { 17 return new(blackhole.NoneResponse), nil 18 } 19 20 type HTTPResponse struct{} 21 22 func (*HTTPResponse) Build() (proto.Message, error) { 23 return new(blackhole.HTTPResponse), nil 24 } 25 26 type BlackholeConfig struct { 27 Response json.RawMessage `json:"response"` 28 } 29 30 func (v *BlackholeConfig) Build() (proto.Message, error) { 31 config := new(blackhole.Config) 32 if v.Response != nil { 33 response, _, err := configLoader.Load(v.Response) 34 if err != nil { 35 return nil, newError("Config: Failed to parse Blackhole response config.").Base(err) 36 } 37 responseSettings, err := response.(cfgcommon.Buildable).Build() 38 if err != nil { 39 return nil, err 40 } 41 config.Response = serial.ToTypedMessage(responseSettings) 42 } 43 44 return config, nil 45 } 46 47 var configLoader = loader.NewJSONConfigLoader( 48 loader.ConfigCreatorCache{ 49 "none": func() interface{} { return new(NoneResponse) }, 50 "http": func() interface{} { return new(HTTPResponse) }, 51 }, 52 "type", 53 "")