ahenk-go/pkg/utils/main.go

50 lines
774 B
Go
Raw Normal View History

package utils
import (
"log"
"os"
)
func Byte2String(arr []int8) string {
b := make([]byte, len(arr))
for i, v := range arr {
b[i] = byte(v)
}
return string(b)
}
func Byte2MiB(b uint64) float64 {
return float64(float64(b) / (1024 * 1024))
}
func Byte2GiB(b uint64) float64 {
return float64(float64(b) / (1024 * 1024 * 1024))
}
func CheckPath(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
func CreatePath(path string) {
if flag, err := CheckPath(path); flag {
if err != nil {
log.Fatal(err)
}
} else if err := os.Mkdir(path, os.ModePerm); err != nil {
log.Fatal(err)
}
}
func Check(err error) {
if err != nil {
panic(err)
}
}