util

package
v0.0.0-...-453d458 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadonlyFilePerm = 0555
	NormalFilePerm   = 0666
	NormalFolerPerm  = 0750
)

Variables

Functions

func Base64Decode

func Base64Decode(s Base64String) ([]byte, error)

func CheckFileName

func CheckFileName(tempFile string) error

CheckFileName 尝试创建文件, 以确保文件名合法.

func CheckTime

func CheckTime(layout, value string) error

CheckTime 检查时间字符串是否符合指定格式.

func CopyAndLockFile

func CopyAndLockFile(dstPath, srcPath string) error

func CopyAndUnlockFile

func CopyAndUnlockFile(dstPath, srcPath string) error

func CreateFile

func CreateFile(filePath string, src io.Reader) error

CreateFile 把 src 的数据写入 filePath, 自动关闭 file.

func CreateReturnFile

func CreateReturnFile(filePath string, src io.Reader) (*os.File, error)

CreateReturnFile 把 src 的数据写入 filePath 会自动创建或覆盖文件,返回 file, 要记得关闭资源。

func DeleteFiles

func DeleteFiles(files []string) (err error)

func DirIsEmpty

func DirIsEmpty(dirpath string) (ok bool, err error)

func DirIsNotEmpty

func DirIsNotEmpty(dirpath string) (ok bool, err error)

func GetExePath

func GetExePath() string

GetExePath returns the path name for the executable that started the current process.

func GetRegularFiles

func GetRegularFiles(folder string) (files []string, err error)

func IsRegularFile

func IsRegularFile(name string) (ok bool, err error)

func LockFile

func LockFile(name string) error

LockFile 把檔案设为只读权限 (不可写)

func Mkdir

func Mkdir(name string) error

func MkdirIfNotExists

func MkdirIfNotExists(name string) error

MkdirIfNotExists 创建資料夹, 忽略 ErrExist. 在 Windows 里, 文件夹的只读属性不起作用, 为了统一行为, 不把文件夹设为只读.

func OneWaySyncDir

func OneWaySyncDir(srcDir, dstDir string) error

func PathExists

func PathExists(name string) bool

func PathNotExists

func PathNotExists(name string) (ok bool)

TODO: 改名 PathNotExists

func SamePath

func SamePath(path1, path2 string) (yes bool, err error)

func UnlockFile

func UnlockFile(name string) error

UnlockFile 把檔案设为可读写.

func WrapErrors

func WrapErrors(allErrors ...error) (wrapped error)

WrapErrors 把多个错误合并为一个错误.

func WriteFile

func WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile 写檔案, 如果 perm 等于零, 则使用默认权限.

func WriteJSON

func WriteJSON(data interface{}, filename string) error

WriteJSON 把 data 转换为漂亮格式的 JSON 并写入檔案 filename 中。

func WriteReadonlyFile

func WriteReadonlyFile(name string, data []byte) error

WriteReadonlyFile 写檔案, 同时把檔案设为只读.

func WriteTOML

func WriteTOML(data interface{}, filename string) error

Types

type Base64String

type Base64String = string

func Base64Encode

func Base64Encode(data []byte) Base64String

type HexString

type HexString = string

func FileSum512

func FileSum512(name string) (HexString, error)

BLAKE2b is faster than MD5, SHA-1, SHA-2, and SHA-3, on 64-bit x86-64 and ARM architectures. https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2 https://blog.min.io/fast-hashing-in-golang-using-blake2/ https://pkg.go.dev/crypto/sha256#example-New-File

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL