v2ray-core/main/json/config_json.go

38 lines
902 B
Go
Raw Normal View History

package json
2018-09-30 23:08:41 +02:00
//go:generate errorgen
2016-10-16 00:46:30 +02:00
import (
"io"
"v2ray.com/core"
2018-02-12 11:40:42 +01:00
"v2ray.com/core/common"
2018-11-18 19:36:36 +01:00
"v2ray.com/core/common/buf"
2019-12-14 23:29:54 +08:00
"v2ray.com/core/common/cmdarg"
2018-04-08 23:22:55 +02:00
"v2ray.com/core/common/platform/ctlcmd"
2019-12-14 23:29:54 +08:00
"v2ray.com/core/infra/conf/serial"
)
func init() {
2018-02-14 23:57:40 +01:00
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
Name: "JSON",
Extension: []string{"json"},
2019-12-14 23:29:54 +08:00
Loader: func(input interface{}) (*core.Config, error) {
switch v := input.(type) {
case cmdarg.Arg:
jsonContent, err := ctlcmd.Run(append([]string{"config"}, v...), nil)
if err != nil {
return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning()
}
return core.LoadConfig("protobuf", "", &buf.MultiBufferContainer{
MultiBuffer: jsonContent,
})
case io.Reader:
return serial.LoadJSONConfig(v)
default:
return nil, newError("unknow type")
2018-02-14 23:57:40 +01:00
}
},
2018-02-12 11:40:42 +01:00
}))
}