mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
Feat: add JSONC support to v5 configuration
This commit is contained in:
parent
5d3915c751
commit
28d197b6f3
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/v2fly/v2ray-core/v5/common"
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/buf"
|
"github.com/v2fly/v2ray-core/v5/common/buf"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/cmdarg"
|
"github.com/v2fly/v2ray-core/v5/common/cmdarg"
|
||||||
|
"github.com/v2fly/v2ray-core/v5/infra/conf/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
const jsonV5 = "jsonv5"
|
const jsonV5 = "jsonv5"
|
||||||
@ -14,7 +15,7 @@ const jsonV5 = "jsonv5"
|
|||||||
func init() {
|
func init() {
|
||||||
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
|
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
|
||||||
Name: []string{jsonV5},
|
Name: []string{jsonV5},
|
||||||
Extension: []string{".v5.json"},
|
Extension: []string{".v5.json", ".v5.jsonc"},
|
||||||
Loader: func(input interface{}) (*core.Config, error) {
|
Loader: func(input interface{}) (*core.Config, error) {
|
||||||
switch v := input.(type) {
|
switch v := input.(type) {
|
||||||
case string:
|
case string:
|
||||||
@ -22,13 +23,17 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := buf.ReadAllToBytes(r)
|
data, err := buf.ReadAllToBytes(&json.Reader{
|
||||||
|
Reader: r,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return loadJSONConfig(data)
|
return loadJSONConfig(data)
|
||||||
case io.Reader:
|
case io.Reader:
|
||||||
data, err := buf.ReadAllToBytes(v)
|
data, err := buf.ReadAllToBytes(&json.Reader{
|
||||||
|
Reader: v,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user