2018-02-17 21:22:51 +01:00
|
|
|
package json
|
|
|
|
|
2018-09-30 23:08:41 +02:00
|
|
|
//go:generate errorgen
|
2016-10-16 00:46:30 +02:00
|
|
|
|
2017-11-11 22:29:00 +01: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"
|
2018-04-08 23:22:55 +02:00
|
|
|
"v2ray.com/core/common/platform/ctlcmd"
|
2017-11-11 22:29:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2018-02-14 23:57:40 +01:00
|
|
|
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
|
|
|
|
Name: "JSON",
|
|
|
|
Extension: []string{"json"},
|
|
|
|
Loader: func(input io.Reader) (*core.Config, error) {
|
2018-04-08 23:22:55 +02:00
|
|
|
jsonContent, err := ctlcmd.Run([]string{"config"}, input)
|
2018-02-14 23:57:40 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning()
|
|
|
|
}
|
2018-11-18 19:36:36 +01:00
|
|
|
return core.LoadConfig("protobuf", "", &buf.MultiBufferContainer{
|
|
|
|
MultiBuffer: jsonContent,
|
|
|
|
})
|
2018-02-14 23:57:40 +01:00
|
|
|
},
|
2018-02-12 11:40:42 +01:00
|
|
|
}))
|
2017-11-11 22:29:00 +01:00
|
|
|
}
|