1 Star 1 Fork 0

dreamwood/EZ框架核心

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
yml.go 685 Bytes
一键复制 编辑 原始数据 按行查看 历史
dreamwood 提交于 2022-12-18 21:55 +08:00 . goto work
package ez
import (
"gopkg.in/yaml.v2"
)
type YmlConfig struct {
FilePath string
}
func CreateConfigFromYml(path string, node string, model interface{}) {
yc := new(YmlConfig)
yc.SetFilePath(path)
all := make(map[string]interface{})
yc.FillModel(&all)
nodeData, ok := all[node]
if !ok {
return
}
tmp, e := yaml.Marshal(nodeData)
if e != nil {
PrintError(e)
return
}
e = yaml.Unmarshal(tmp, model)
PrintError(e)
}
func (this *YmlConfig) SetFilePath(path string) {
this.FilePath = path
}
func (this *YmlConfig) FillModel(model interface{}) {
content := FindAndOpen(this.FilePath)
if content != nil {
e := yaml.Unmarshal(content, model)
PrintError(e)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dreamwood/ez.git
git@gitee.com:dreamwood/ez.git
dreamwood
ez
EZ框架核心
v1.0.2

搜索帮助