Skip to content

Commit 0818aa5

Browse files
committed
chore: provider a common entrance for YAML package
1 parent edbfebe commit 0818aa5

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

adapter/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/metacubex/mihomo/adapter"
1414
"github.com/metacubex/mihomo/common/convert"
1515
"github.com/metacubex/mihomo/common/utils"
16+
"github.com/metacubex/mihomo/common/yaml"
1617
"github.com/metacubex/mihomo/component/profile/cachefile"
1718
"github.com/metacubex/mihomo/component/resource"
1819
C "github.com/metacubex/mihomo/constant"
@@ -21,7 +22,6 @@ import (
2122

2223
"github.com/dlclark/regexp2"
2324
"github.com/metacubex/http"
24-
"gopkg.in/yaml.v3"
2525
)
2626

2727
const (

common/yaml/yaml.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Package yaml provides a common entrance for YAML marshaling and unmarshalling.
2+
package yaml
3+
4+
import (
5+
"gopkg.in/yaml.v3"
6+
)
7+
8+
func Unmarshal(in []byte, out any) (err error) {
9+
return yaml.Unmarshal(in, out)
10+
}
11+
12+
func Marshal(in any) (out []byte, err error) {
13+
return yaml.Marshal(in)
14+
}

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/metacubex/mihomo/adapter/outboundgroup"
1717
"github.com/metacubex/mihomo/adapter/provider"
1818
"github.com/metacubex/mihomo/common/utils"
19+
"github.com/metacubex/mihomo/common/yaml"
1920
"github.com/metacubex/mihomo/component/auth"
2021
"github.com/metacubex/mihomo/component/cidr"
2122
"github.com/metacubex/mihomo/component/fakeip"
@@ -39,7 +40,6 @@ import (
3940

4041
orderedmap "github.com/wk8/go-ordered-map/v2"
4142
"golang.org/x/exp/slices"
42-
"gopkg.in/yaml.v3"
4343
)
4444

4545
// General config

rules/provider/provider.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import (
1010
"time"
1111

1212
"github.com/metacubex/mihomo/common/pool"
13+
"github.com/metacubex/mihomo/common/yaml"
1314
"github.com/metacubex/mihomo/component/resource"
1415
C "github.com/metacubex/mihomo/constant"
1516
P "github.com/metacubex/mihomo/constant/provider"
1617
"github.com/metacubex/mihomo/rules/common"
17-
18-
"gopkg.in/yaml.v3"
1918
)
2019

2120
var tunnel P.Tunnel

0 commit comments

Comments
 (0)