1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 01:27:03 -05:00
v2fly/infra/conf/v5cfg/init.go
2021-10-28 18:34:19 +08:00

42 lines
879 B
Go

package v5cfg
import (
"io"
core "github.com/v2fly/v2ray-core/v4"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/buf"
"github.com/v2fly/v2ray-core/v4/common/cmdarg"
)
const jsonV5 = "jsonv5"
func init() {
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
Name: []string{jsonV5},
Extension: []string{".v5.json"},
Loader: func(input interface{}) (*core.Config, error) {
switch v := input.(type) {
case string:
r, err := cmdarg.LoadArg(v)
if err != nil {
return nil, err
}
data, err := buf.ReadAllToBytes(r)
if err != nil {
return nil, err
}
return loadJsonConfig(data)
case io.Reader:
data, err := buf.ReadAllToBytes(v)
if err != nil {
return nil, err
}
return loadJsonConfig(data)
default:
return nil, newError("unknown type")
}
},
}))
}