1 Star 0 Fork 0

Uni-Minds / utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
yaml.go 564 Bytes
一键复制 编辑 原始数据 按行查看 历史
Liuxy 提交于 2022-10-15 14:14 . Release 1.0.0
/*
* Copyright (c) 2019-2022
* Author: LIU Xiangyu
* File: yaml.go
*/
package tools
import (
yaml "gopkg.in/yaml.v3"
"os"
"path/filepath"
)
func LoadYaml(path string, i interface{}) error {
if f, err := os.Open(path); err != nil {
return err
} else {
return yaml.NewDecoder(f).Decode(i)
}
}
func SaveYaml(path string, i interface{}) error {
os.MkdirAll(filepath.Dir(path), 0644)
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
if err != nil {
return err
} else {
yaml.NewEncoder(f).Encode(i)
return f.Close()
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/uni-minds/utils.git
git@gitee.com:uni-minds/utils.git
uni-minds
utils
utils
v1.0.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891