2016-01-15 06:43:06 -05:00
|
|
|
// +build json
|
|
|
|
|
|
|
|
package blackhole
|
|
|
|
|
|
|
|
import (
|
2016-06-10 17:01:17 -04:00
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/loader"
|
2016-06-10 16:26:39 -04:00
|
|
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
2016-01-15 06:43:06 -05:00
|
|
|
)
|
|
|
|
|
2016-06-10 16:26:39 -04:00
|
|
|
func (this *Config) UnmarshalJSON(data []byte) error {
|
2016-06-10 17:01:17 -04:00
|
|
|
type JSONConfig struct {
|
|
|
|
Response json.RawMessage `json:"response"`
|
|
|
|
}
|
|
|
|
jsonConfig := new(JSONConfig)
|
|
|
|
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-06-10 17:09:14 -04:00
|
|
|
|
|
|
|
this.Response = new(NoneResponse)
|
2016-06-10 19:32:55 -04:00
|
|
|
if jsonConfig.Response != nil {
|
2016-06-10 17:01:17 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2016-06-10 16:26:39 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-15 06:43:06 -05:00
|
|
|
func init() {
|
2016-06-10 16:26:39 -04:00
|
|
|
internal.RegisterOutboundConfig("blackhole", func() interface{} { return new(Config) })
|
2016-01-15 06:43:06 -05:00
|
|
|
}
|