初始化

This commit is contained in:
Yun
2024-04-13 10:34:22 +08:00
commit 9913cfa952
3 changed files with 30 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
module code.yun.ink/pkg/yamlx
go 1.20
require gopkg.in/yaml.v2 v2.4.0
+4
View File
@@ -0,0 +1,4 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
+21
View File
@@ -0,0 +1,21 @@
package yamlx
import (
"log"
"os"
"gopkg.in/yaml.v2"
)
// 初始化配置
func InitConfig(path string, onfigData interface{}) {
data, err := os.ReadFile(path)
if err != nil {
log.Panicf("read config file error,%v", err)
}
err = yaml.Unmarshal(data, &onfigData)
if err != nil {
log.Panicf("parse config file error, %v", err)
}
}