golang file utils for common use
To get the package, execute:
go get github.com/gofika/fileutil
package main
import (
"fmt"
"github.com/gofika/fileutil"
)
func main() {
name := "foo/bar.txt"
data := []byte("Hello")
// write data to file. will create dir: foo
err := fileutil.WriteFile(name, data)
if err != nil {
fmt.Printf("Write file failed. err: %s\n", err.Error())
return
}
// check file exist
if !fileutil.IsExist(name) {
fmt.Printf("file %s not exist.\n", name)
return
}
// clear temp file
fileutil.DeleteAll("foo")
}