package
0.0.0-20231013025015-df225fcd9425
Repository: https://github.com/ccmonky/pkg.git
Documentation: pkg.go.dev
# README
pkg
utility package
# Functions
Abs for int64.
AfterEqualWithSkew 在时间偏差为d的情况下判断时间a >= b.
AfterWithSkew 在时间偏差为d的情况下判断时间a > b.
No description provided by the author
BeforeEqualWithSkew 在时间偏差为d的情况下判断时间a <= b.
BeforeWithSkew 在时间偏差为d的情况下判断时间a < b.
Compare 比较新旧两个列表,返回新增和删除列表.
Contains check if element in list, used to test.
Divmod like python divmod.
EncodeFormToBody refill `r.Form` into `r.Body`, usually used in reverse proxy Limit: support only `PostForm` not, not implement for `Multipart`.
EncodeMultipartFormToBody 未实现,最好不要用于反代!.
EncodePostFormToBody detect if has executed `request.ParseForm`, if yes then refill the `r.Body`.
ExecuteTemplate used to test template and funcs.
FuncName return func name of func fn.
GetLocalIp 获取本机IP.
GetRequestID 用于从context中提取请求ID.
HashCode return the hash value of bytes slice p.
Index returns the index of the first instance of elem in list, or -1 if elem is not present in list.
Indirect returns the item at the end of Indirection.
InterfaceName return interface name of an interface value.
IsBodyDrained 判断请求的Body是否已读取,如果返回io.EOF或http.ErrBodyReadAfterClose认为已读取,另外,如果Body为nil,也返回true.
IsHTTPMethodValid test if method is valid http method.
IsNil 判断是否为nil.
IsSpaceOr 用作strings.FieldsFunc的分割函数生成器, 效果上相当于用sep分割,同时去掉空格 strings.FieldsFunc("parking| def", isSpaceOr('|')) -> [parking def], 而不是[parking def].
IsZero 判断对象是否为零值.
Map 模拟python的map函数.
MustUlid 生成Ulid返回string,失败panic.
No description provided by the author
NewHash return the new hash code copy from `https://gist.github.com/giautm/d79994acd796f3065903eccbc8d6e09b`.
No description provided by the author
PanicIfError panic if err != nil.
ParseCertificateFromPEM parse certificate from pem data.
PathExists determine if a file or directory exists.
PkgFuncName return package and func name of func fn.
PkgPath return package path of value v.
PkgPath return package and type name of value v.
RandASCIIBytes - A helper function create and fill a slice of length n with characters from a-zA-Z0-9_-.
Random return a integer with in [min, max).
RandomString - Generate a random string of A-Z chars with len = l.
RandStringBytes - generate random string using bytes.
RandStringBytesMask - generate random string using masking.
RandStringBytesMaskImpr - generate random string using masking improved.
RandStringBytesMaskImprSrc - generate random string using masking with source.
RandStringBytesRmndr - generate random string using Remainder.
RandStringRunes - generate random string using random int.
RemoveDuplicatesUnordered 字符串列表不保序去重.
Shuffle returns a random distributed slice.
Source returns the `Source` caller's package path, maybe panic NOTE: 1.
SplitByLength 按长度分割字符串.
StringSliceEquals 比较两个字符串数组是否相等.
StringSliceSortEquals 比较两个字符串数组排序后是否相等.
ToLowerFirst 将第一个字符转为小写.
No description provided by the author
TryGetFirstByteOfRequestBody try to read first byte of http request body, and then fill back to body.
No description provided by the author
No description provided by the author
PkgPath return type name of value v.
Ulid 生成Ulid返回string.
Unzip used to unzip all files in a request body with zip archived.
UnzipFirst used to unzip first file in a request body with zip archived.
WeightedChoice used for weighted random selection.
WithoutCancel returns a context that is never canceled.
ZapJSON 使用json序列化对象的zao.Field.
ZapRequestID 获取http请求ID的zao.Field.
Zip compress the payload and return zip bytes, file name pattern is `file\d+`.
# Constants
RequestIDKey is the key that holds th unique request ID in a request context.
RequestIDName defines the name of request ID in log.
# Variables
ErrNotImplemented not implement error.
# Interfaces
JavaStringHashCode simultes the java.io.String.hashCode method.