mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-23 07:23:01 +00:00
079d0bd8a9
* Refactor log * Add new log methods * Fix logger test * Change all logging code * Clean up pathObj * Rebase to latest main * Remove invoking method name after the dot
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package conf
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/xtls/xray-core/common/errors"
|
|
"github.com/xtls/xray-core/common/serial"
|
|
"github.com/xtls/xray-core/proxy/blackhole"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type NoneResponse struct{}
|
|
|
|
func (*NoneResponse) Build() (proto.Message, error) {
|
|
return new(blackhole.NoneResponse), nil
|
|
}
|
|
|
|
type HTTPResponse struct{}
|
|
|
|
func (*HTTPResponse) Build() (proto.Message, error) {
|
|
return new(blackhole.HTTPResponse), nil
|
|
}
|
|
|
|
type BlackholeConfig struct {
|
|
Response json.RawMessage `json:"response"`
|
|
}
|
|
|
|
func (v *BlackholeConfig) Build() (proto.Message, error) {
|
|
config := new(blackhole.Config)
|
|
if v.Response != nil {
|
|
response, _, err := configLoader.Load(v.Response)
|
|
if err != nil {
|
|
return nil, errors.New("Config: Failed to parse Blackhole response config.").Base(err)
|
|
}
|
|
responseSettings, err := response.(Buildable).Build()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
config.Response = serial.ToTypedMessage(responseSettings)
|
|
}
|
|
|
|
return config, nil
|
|
}
|
|
|
|
var configLoader = NewJSONConfigLoader(
|
|
ConfigCreatorCache{
|
|
"none": func() interface{} { return new(NoneResponse) },
|
|
"http": func() interface{} { return new(HTTPResponse) },
|
|
},
|
|
"type",
|
|
"")
|