You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/proxy/blackhole/config_json.go

39 lines
934 B

// +build json
package blackhole
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/loader"
"github.com/v2ray/v2ray-core/proxy/internal"
)
func (this *Config) UnmarshalJSON(data []byte) error {
type JSONConfig struct {
Response json.RawMessage `json:"response"`
}
jsonConfig := new(JSONConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
if jsonConfig.Response == nil {
this.Response = new(NoneResponse)
} else {
loader := loader.NewJSONConfigLoader("type", "")
loader.RegisterCreator("none", func() interface{} { return new(NoneResponse) })
loader.RegisterCreator("http", func() interface{} { return new(HTTPResponse) })
response, err := loader.Load(jsonConfig.Response)
if err != nil {
return err
}
this.Response = response.(Response)
}
return nil
}
func init() {
internal.RegisterOutboundConfig("blackhole", func() interface{} { return new(Config) })
}