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