From 0818aa54aa0bca6da40d993b11c7976028ed4588 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 16 Jan 2026 08:59:29 +0800 Subject: [PATCH] chore: provider a common entrance for YAML package --- adapter/provider/provider.go | 2 +- common/yaml/yaml.go | 14 ++++++++++++++ config/config.go | 2 +- rules/provider/provider.go | 3 +-- 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 common/yaml/yaml.go diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index ff21fe89..c9007892 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -13,6 +13,7 @@ import ( "github.com/metacubex/mihomo/adapter" "github.com/metacubex/mihomo/common/convert" "github.com/metacubex/mihomo/common/utils" + "github.com/metacubex/mihomo/common/yaml" "github.com/metacubex/mihomo/component/profile/cachefile" "github.com/metacubex/mihomo/component/resource" C "github.com/metacubex/mihomo/constant" @@ -21,7 +22,6 @@ import ( "github.com/dlclark/regexp2" "github.com/metacubex/http" - "gopkg.in/yaml.v3" ) const ( diff --git a/common/yaml/yaml.go b/common/yaml/yaml.go new file mode 100644 index 00000000..769f7f5f --- /dev/null +++ b/common/yaml/yaml.go @@ -0,0 +1,14 @@ +// Package yaml provides a common entrance for YAML marshaling and unmarshalling. +package yaml + +import ( + "gopkg.in/yaml.v3" +) + +func Unmarshal(in []byte, out any) (err error) { + return yaml.Unmarshal(in, out) +} + +func Marshal(in any) (out []byte, err error) { + return yaml.Marshal(in) +} diff --git a/config/config.go b/config/config.go index 362e4e27..68b2b1ee 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,7 @@ import ( "github.com/metacubex/mihomo/adapter/outboundgroup" "github.com/metacubex/mihomo/adapter/provider" "github.com/metacubex/mihomo/common/utils" + "github.com/metacubex/mihomo/common/yaml" "github.com/metacubex/mihomo/component/auth" "github.com/metacubex/mihomo/component/cidr" "github.com/metacubex/mihomo/component/fakeip" @@ -39,7 +40,6 @@ import ( orderedmap "github.com/wk8/go-ordered-map/v2" "golang.org/x/exp/slices" - "gopkg.in/yaml.v3" ) // General config diff --git a/rules/provider/provider.go b/rules/provider/provider.go index f197a80a..0534a838 100644 --- a/rules/provider/provider.go +++ b/rules/provider/provider.go @@ -10,12 +10,11 @@ import ( "time" "github.com/metacubex/mihomo/common/pool" + "github.com/metacubex/mihomo/common/yaml" "github.com/metacubex/mihomo/component/resource" C "github.com/metacubex/mihomo/constant" P "github.com/metacubex/mihomo/constant/provider" "github.com/metacubex/mihomo/rules/common" - - "gopkg.in/yaml.v3" ) var tunnel P.Tunnel