1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package util
- import (
- "encoding/binary"
- "fmt"
- )
- // 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
- }
|