package file import ( "git.0x7f.app/WOJ/woj-server/pkg/utils" "io" "os" "path/filepath" ) func Read(filePath string) ([]byte, error) { f, err := os.Open(filePath) if err != nil { return nil, err } return io.ReadAll(f) } func Write(filePath string, content []byte) error { return os.WriteFile(filePath, content, 0644) } func Exist(filePath string) bool { _, err := os.Stat(filePath) return utils.If(err == nil || os.IsExist(err), true, false) } func Empty(filePath string) bool { stat, err := os.Stat(filePath) if err != nil { return true } return stat.Size() == 0 } func Touch(filePath string) bool { err := TouchErr(filePath) return utils.If(err == nil, true, false) } func TouchErr(filePath string) error { base := filepath.Dir(filePath) _ = os.MkdirAll(base, 0755) _, err := os.OpenFile(filePath, os.O_RDONLY|os.O_CREATE, 0644) return err }