2021-09-04 14:54:07 -04:00
|
|
|
package v5cfg
|
|
|
|
|
|
|
|
import (
|
|
|
|
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"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
const jsonV5 = "jsonv5"
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
|
|
|
|
Name: []string{jsonV5},
|
2021-09-04 17:56:23 -04:00
|
|
|
Extension: []string{".v5.json"},
|
2021-09-04 14:54:07 -04:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|