Skip to content

Commit 95cb951

Browse files
committed
feat(项目): 完成接入
1 parent 0eeb76a commit 95cb951

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

go.mod

+34-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,38 @@ go 1.23
55
require (
66
github.com/goexl/exception v0.0.1
77
github.com/goexl/gox v1.8.5
8-
github.com/pangum/config v0.0.5
8+
github.com/pangum/config v0.0.6
9+
github.com/pangum/pangu v1.4.2
10+
gopkg.in/yaml.v3 v3.0.1
11+
)
12+
13+
require (
14+
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
15+
github.com/drone/envsubst v1.0.3 // indirect
16+
github.com/fsnotify/fsnotify v1.7.0 // indirect
17+
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
18+
github.com/go-playground/locales v0.14.1 // indirect
19+
github.com/go-playground/universal-translator v0.18.1 // indirect
20+
github.com/go-playground/validator/v10 v10.22.1 // indirect
21+
github.com/goexl/baozheng v0.0.1 // indirect
22+
github.com/goexl/env v0.0.2 // indirect
23+
github.com/goexl/gfx v0.2.1 // indirect
24+
github.com/goexl/log v0.0.7 // indirect
25+
github.com/goexl/mengpo v0.2.6 // indirect
26+
github.com/goexl/xiren v0.0.6 // indirect
27+
github.com/google/uuid v1.6.0 // indirect
28+
github.com/leodido/go-urn v1.4.0 // indirect
29+
github.com/mattn/go-runewidth v0.0.16 // indirect
30+
github.com/olekukonko/tablewriter v0.0.5 // indirect
31+
github.com/rivo/uniseg v0.4.7 // indirect
32+
github.com/rs/xid v1.6.0 // indirect
33+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
34+
github.com/urfave/cli/v2 v2.27.4 // indirect
35+
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
36+
github.com/zs5460/art v0.3.0 // indirect
37+
go.uber.org/dig v1.18.0 // indirect
38+
golang.org/x/crypto v0.27.0 // indirect
39+
golang.org/x/net v0.29.0 // indirect
40+
golang.org/x/sys v0.25.0 // indirect
41+
golang.org/x/text v0.18.0 // indirect
942
)

internal/loader.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package internal
22

33
import (
44
"context"
5-
"encoding/json"
65
"path/filepath"
76
"strings"
87

98
"github.com/goexl/exception"
109
"github.com/goexl/gox/field"
1110
"github.com/pangum/config"
11+
"gopkg.in/yaml.v3"
1212
)
1313

1414
var _ config.Loader = (*Loader)(nil)
@@ -23,22 +23,27 @@ func (l *Loader) Local() bool {
2323
return true
2424
}
2525

26-
func (l *Loader) Load(ctx context.Context, target any) (err error) {
26+
func (l *Loader) Load(ctx context.Context, target any) (loaded bool, err error) {
2727
if path, pok := ctx.Value(config.ContextFilepath).(string); !pok {
2828
err = exception.New().Message("未指定配置文件路径").Field(field.New("loader", "yaml")).Build()
2929
} else if bytes, bok := ctx.Value(config.ContextBytes).([]byte); !bok {
3030
err = exception.New().Message("配置文件无内容").Field(field.New("loader", "yaml")).Build()
3131
} else {
32-
err = l.load(&path, &bytes, target)
32+
loaded, err = l.load(&path, &bytes, target)
3333
}
3434

3535
return
3636
}
3737

38-
func (l *Loader) load(path *string, bytes *[]byte, target any) (err error) {
38+
func (l *Loader) load(path *string, bytes *[]byte, target any) (loaded bool, err error) {
3939
ext := strings.ToLower(filepath.Ext(*path))
40+
loadable := false
4041
if ".yaml" == ext || ".yml" == ext {
41-
err = json.Unmarshal(*bytes, target)
42+
loadable = true
43+
err = yaml.Unmarshal(*bytes, target)
44+
}
45+
if nil == err && loadable {
46+
loaded = true
4247
}
4348

4449
return

pangu.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package yaml
2+
3+
import (
4+
"github.com/pangum/pangu"
5+
"github.com/pangum/yaml/internal"
6+
)
7+
8+
func init() {
9+
pangu.New().Config().Loader(internal.NewLoader()).Build()
10+
}

yaml.go

-9
This file was deleted.

0 commit comments

Comments
 (0)