woj-server/pkg/utils/file.go
Paul Pan 26a81652b3 feat: another big update
1. add consumer
2. add createVersion
3. add upload
4. fix runner
5. add rejudge

Co-authored-by: cxy004 <cxy004@qq.com>
Co-authored-by: wzt <w.zhongtao@qq.com>
2022-10-23 17:29:35 +08:00

40 lines
777 B
Go

package utils
import (
"io"
"os"
"path/filepath"
)
func FileRead(filePath string) ([]byte, error) {
f, err := os.Open(filePath)
if err != nil {
return nil, err
}
return io.ReadAll(f)
}
func FileWrite(filePath string, content []byte) error {
return os.WriteFile(filePath, content, 0644)
}
func FileExist(filePath string) bool {
_, err := os.Stat(filePath)
return If(err == nil || os.IsExist(err), true, false).(bool)
}
func FileEmpty(filePath string) bool {
stat, err := os.Stat(filePath)
if err != nil {
return true
}
return stat.Size() == 0
}
func FileTouch(filePath string) bool {
base := filepath.Dir(filePath)
_ = os.MkdirAll(base, 0755)
_, err := os.OpenFile(filePath, os.O_RDONLY|os.O_CREATE, 0644)
return If(err == nil, true, false).(bool)
}