diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 58a899177..a09b23a13 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,7 +7,14 @@ assignees: inhere --- +**System (please complete the following information):** + + - OS: `linux` [e.g. linux, macOS] + - GO Version: `1.13` [e.g. `1.13`] + - Pkg Version: `1.1.1` [e.g. `1.1.1`] + **Describe the bug** + A clear and concise description of what the bug is. **To Reproduce** @@ -17,15 +24,13 @@ A clear and concise description of what the bug is. ``` **Expected behavior** + A clear and concise description of what you expected to happen. **Screenshots** -If applicable, add screenshots to help explain your problem. -**System (please complete the following information):** - - OS: [e.g. Linux] - - GO version [e.g. 1.13] - - Pkg Version [e.g. 1.1.1] +If applicable, add screenshots to help explain your problem. **Additional context** + Add any other context about the problem here. diff --git a/fsutil/filesystem.go b/fsutil/filesystem.go index 1e58a444b..6e2a3f828 100644 --- a/fsutil/filesystem.go +++ b/fsutil/filesystem.go @@ -31,6 +31,10 @@ var ( } ) +// var ( +// ReadFile = ioutil.ReadFile +// ) + // FileExists reports whether the named file or directory exists. // Deprecated // please use PathExists() or IsFile() instead it @@ -86,6 +90,23 @@ func Mkdir(dirPath string, perm os.FileMode) error { return os.MkdirAll(dirPath, perm) } +// OpenFile like os.OpenFile, but will auto create dir. +func OpenFile(filepath string, flag int, mode int) (*os.File, error) { + fileDir := path.Dir(filepath) + + // if err := os.Mkdir(dir, 0777); err != nil { + if err := os.MkdirAll(fileDir, 0777); err != nil { + return nil, err + } + + file, err := os.OpenFile(filepath, flag, os.FileMode(mode)) + if err != nil { + return nil, err + } + + return file, nil +} + // CreateFile if not exists // Usage: // CreateFile("path/to/file.txt", 0664, 0666)