diff --git a/sysutils.go b/sysutils.go index c7fb225..823d73e 100644 --- a/sysutils.go +++ b/sysutils.go @@ -1,18 +1,18 @@ package q5 import ( + "bufio" "encoding/json" "fmt" + "hash/crc32" "io/ioutil" "net" "net/http" "os" "reflect" - "time" - "sync" "runtime" - "hash/crc32" - "bufio" + "sync" + "time" ) func GetDaySeconds(seconds int64, timeZone int64) int64 { @@ -207,7 +207,7 @@ func NewSlice[T any](s *[]T, len int32, cap int32) { func NewSliceElement[T any](s *[]T) *T { v := new(T) *s = append(*s, *v) - return &(*s)[len(*s) - 1] + return &(*s)[len(*s)-1] } func AppendSlice[T any](s *[]T, val T) { @@ -219,7 +219,7 @@ func GetTypeName(v interface{}) string { } func PrintCallStack() { -// 获取当前函数的调用者信息 + // 获取当前函数的调用者信息 pc, file, line, ok := runtime.Caller(1) if !ok { fmt.Println("runtime.Caller error") @@ -242,7 +242,7 @@ func PrintCallStack() { } func GetCallStack() string { -// 获取当前函数的调用者信息 + // 获取当前函数的调用者信息 //pc, file, line, ok := runtime.Caller(1) _, _, _, ok := runtime.Caller(1) if !ok { @@ -353,11 +353,20 @@ func CreateCondTimer(ch chan int64, cond *sync.Cond, initSeconds int64) { } } -func ExcUntilOk(cb func()bool) { +func ExcUntilOk(cb func() bool) { for !cb() { } } +func ReadTextFile(fileName string) (string, error) { + if f, err := os.Open(fileName); err == nil { + data, err := ioutil.ReadAll(bufio.NewReader(f)) + return string(data), err + } else { + return "", err + } +} + func IsDebug() bool { return true }