From 28d197b6f37864e2d1465590bd4fde8c16c0cb72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E3=81=AE=E3=81=8B=E3=81=88=E3=81=A7?= Date: Mon, 9 May 2022 23:28:34 +0800 Subject: [PATCH] Feat: add JSONC support to v5 configuration --- infra/conf/v5cfg/init.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/infra/conf/v5cfg/init.go b/infra/conf/v5cfg/init.go index 2b528c5c4..db2d5cacf 100644 --- a/infra/conf/v5cfg/init.go +++ b/infra/conf/v5cfg/init.go @@ -7,6 +7,7 @@ import ( "github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common/buf" "github.com/v2fly/v2ray-core/v5/common/cmdarg" + "github.com/v2fly/v2ray-core/v5/infra/conf/json" ) const jsonV5 = "jsonv5" @@ -14,7 +15,7 @@ const jsonV5 = "jsonv5" func init() { common.Must(core.RegisterConfigLoader(&core.ConfigFormat{ Name: []string{jsonV5}, - Extension: []string{".v5.json"}, + Extension: []string{".v5.json", ".v5.jsonc"}, Loader: func(input interface{}) (*core.Config, error) { switch v := input.(type) { case string: @@ -22,13 +23,17 @@ func init() { if err != nil { return nil, err } - data, err := buf.ReadAllToBytes(r) + data, err := buf.ReadAllToBytes(&json.Reader{ + Reader: r, + }) if err != nil { return nil, err } return loadJSONConfig(data) case io.Reader: - data, err := buf.ReadAllToBytes(v) + data, err := buf.ReadAllToBytes(&json.Reader{ + Reader: v, + }) if err != nil { return nil, err }