mirror of
https://github.com/pyihe/go-pkg.git
synced 2025-09-27 20:32:12 +08:00
31 lines
591 B
Go
31 lines
591 B
Go
package files
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
// NewPath 判断目录是否存在,如果不存在,则新建一个目录
|
|
func NewPath(targetPath string) error {
|
|
if _, err := os.Stat(targetPath); err != nil {
|
|
if !os.IsExist(err) {
|
|
//创建目录
|
|
if mErr := os.MkdirAll(targetPath, os.ModePerm); mErr != nil {
|
|
return mErr
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// LoadJSONFile 加载JSON文件
|
|
func LoadJSONFile(file string, dst interface{}) error {
|
|
content, err := ioutil.ReadFile(file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = json.Unmarshal(content, dst)
|
|
return err
|
|
}
|