package util import ( "encoding/binary" "fmt" ) // Panic with test func Panic(err error) { if err != nil { panic(err) } } // Panicf with test func Panicf(format string, err error) { if err != nil { panic(fmt.Errorf(format, err)) } } // PanicfArgs with test func PanicfArgs(err error, format string, args ...interface{}) { if err != nil { panic(fmt.Errorf(format, args...)) } } // Check error function func Check(format string, args ...interface{}) { var hasError bool for _, v := range args { if err, ok := v.(error); ok && err != nil { hasError = true break } } if hasError { panic(fmt.Errorf(format, args...)) } } // Uint64ToBytes func func Uint64ToBytes(v uint64) []byte { bb := make([]byte, 8) binary.LittleEndian.PutUint64(bb, v) return bb } // UintToBytes func func UintToBytes(v uint) []byte { bb := make([]byte, 4) binary.LittleEndian.PutUint32(bb, uint32(v)) return bb } // InStringSlice func func InStringSlice(v string, list ...string) bool { for _, vl := range list { if v == vl { return true } } return false }