github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/util/alias.go (about) 1 package util 2 3 type ( 4 TErrCode = uint16 5 ) 6 7 type ( 8 Fn func() 9 ToBool func() bool 10 ToInt64 func() int64 11 ToStr func() string 12 ToStrBool func() (string, bool) 13 ToAny func() any 14 ToM func() M 15 ToErr func() *Err 16 ToErrCode func() TErrCode 17 ToFnInt64Fn func() FnStrFn 18 ToMsg func() IMsg 19 FnBool func(bool) 20 BoolToErr func(bool) *Err 21 FnBoolErr func(bool, *Err) 22 FnUint16 func(uint16) 23 FnUint16Bool func(uint16, bool) 24 FnUint16Bytes func(uint16, []byte) 25 FnUint16Err func(uint16, *Err) 26 FnUint162Int642Bytes func(uint16, uint16, int64, int64, []byte) 27 FnUint16Int642Bytes func(uint16, int64, int64, []byte) 28 Uint16ToBool func(uint16) bool 29 Uint16Int64ToUint16 func(uint16, int64) uint16 30 FnInt func(int) 31 FnAnySlc func([]any) 32 FnAnySlc2 func(...any) 33 FnIntAnySlc func(int, []any) 34 FnIntAnySlc2 func(int, []any, []any) 35 FnInt32 func(int32) 36 FnUint32 func(uint32) 37 FnErr func(*Err) 38 FnMsg func(IMsg) 39 FnInt64 func(int64) 40 FnInt64Bool func(int64, bool) 41 FnInt642 func(int64, int64) 42 FnInt64Str func(int64, string) 43 FnInt64Bytes func(int64, []byte) 44 FnInt64M func(int64, M) 45 FnInt64MBytes func(int64, M, []byte) 46 FnInt64Any func(int64, any) 47 FnInt64Err func(int64, *Err) 48 FnInt64MErr func(int64, M, *Err) 49 FnInt643 func(int64, int64, int64) 50 FnInt642Bool func(int64, int64, bool) 51 FnInt642Any func(int64, int64, any) 52 FnInt642Err func(int64, int64, *Err) 53 FnInt64StrBool func(int64, string, bool) 54 FnInt64MUint16 func(int64, M, uint16) 55 FnInt64MMsg func(int64, M, IMsg) 56 Int64ToInt64 func(int64) int64 57 Int64ToStr func(int64) string 58 Int64ToBool func(int64) bool 59 Int64ToErrCode func(int64) TErrCode 60 Int64ToStrErr func(int64) (string, *Err) 61 Int64ToInt64Err func(int64) (int64, *Err) 62 Int64AnyToBool func(int64, any) bool 63 FnStr func(string) 64 StrToBool func(string) bool 65 StrToStr func(string) string 66 FnStrBool func(string, bool) 67 StrIntToBool func(string, int) *Err 68 StrInt64ToBool func(string, int64) *Err 69 FnStrBytes func(string, []byte) 70 FnStrAny func(string, any) 71 FnStrFn func(string, Fn) 72 FnStrErr func(string, *Err) 73 FnStr2Bool func(string, string, bool) 74 StrFnToErr func(string, Fn) *Err 75 StrToStr2Err func(string) (string, string, *Err) 76 StrToBytesErr func(string) ([]byte, *Err) 77 StrAnyToErr func(string, any) *Err 78 StrBytesToBool func(string, []byte) bool 79 Str2Int64ToBoolBytes func(string, string, int64) (bool, *Err) 80 Str2BytesToBytesErr func(string, string, []byte) ([]byte, *Err) 81 Str162ErrToBytesErr func(string, string, *Err) ([]byte, *Err) 82 FnStrSlc func([]string) 83 FnBytes func([]byte) 84 FnBytesSlc func([][]byte) 85 BytesToUint16 func([]byte) uint16 86 BytesToInt func([]byte) int 87 BytesToBytes func([]byte) []byte 88 BytesToM func([]byte) M 89 BytesToErr func([]byte) *Err 90 BytesToInt642Err func([]byte) (int64, int64, *Err) 91 BytesToAnyErr func([]byte) (any, *Err) 92 BytesAnyToError func([]byte, any) error 93 BytesAnyToErr func([]byte, any) *Err 94 FnAny func(any) 95 FnAnyErr func(any, *Err) 96 AnyToBool func(any) bool 97 AnyToInt64 func(any) int64 98 AnyToAny func(any) any 99 AnyToErr func(any) *Err 100 AnyToAnyBool func(any) (any, bool) 101 AnyToBytesError func(any) ([]byte, error) 102 AnyBoolToAnyBool func(any, bool) (any, bool) 103 AnyBoolToBool func(any, bool) bool 104 AnyErrToBool func(any, *Err) bool 105 FnM func(M) 106 FnMBool func(M, bool) 107 FnMAny func(M, any) 108 FnM2Bool func(M, M, bool) 109 MToBool func(M) bool 110 MToInt64 func(M) int64 111 MToAny func(M) any 112 MToBytes func(M) []byte 113 MToErr func(M) *Err 114 FnMErr func(M, *Err) 115 FnMUint32 func(M, uint32) 116 Compare[T any] func(v1, v2 T) int 117 FnMapBool func(map[string]bool) 118 ) 119 120 func Default[T any]() (v T) { 121 return 122 } 123 124 func (f Fn) Invoke() { 125 if f == nil { 126 return 127 } 128 f() 129 } 130 131 func (f FnInt642) Invoke(v1, v2 int64) { 132 if f == nil { 133 return 134 } 135 f(v1, v2) 136 } 137 138 func (f FnInt64Any) Invoke(v int64, obj any) { 139 if f == nil { 140 return 141 } 142 f(v, obj) 143 } 144 145 func (f FnInt64MMsg) Invoke(v int64, head M, obj IMsg) { 146 if f == nil { 147 return 148 } 149 f(v, head, obj) 150 } 151 152 func (f FnErr) Invoke(err *Err) { 153 if f == nil { 154 return 155 } 156 f(err) 157 } 158 159 func (f FnInt64) Invoke(v int64) { 160 if f == nil { 161 return 162 } 163 f(v) 164 } 165 166 func (f FnInt64Str) Invoke(v int64, str string) { 167 if f == nil { 168 return 169 } 170 f(v, str) 171 } 172 173 func (f FnInt64Err) Invoke(v int64, err *Err) { 174 if f == nil { 175 return 176 } 177 f(v, err) 178 } 179 180 func (f FnInt64MErr) Invoke(v int64, head M, err *Err) { 181 if f == nil { 182 return 183 } 184 f(v, head, err) 185 } 186 187 func (f FnStr) Invoke(str string) { 188 if f == nil { 189 return 190 } 191 f(str) 192 } 193 194 func (m M) IndentJson() []byte { 195 bytes, err := JsonMarshalIndent(m, "", " ") 196 if err != nil { 197 panic(err) 198 } 199 return bytes 200 } 201 202 type Id interface { 203 int32 | uint32 | int64 | uint64 | string 204 }