Documentation
¶
Index ¶
- func CheckCustomStructPtrExport(dataPtr any) error
- func CheckMobile(mobile string) bool
- func ClientIP(r *http.Request) string
- func ComparePoint[T comparable](t1, t2 T) bool
- func ConvertStr(col string) string
- func CreateOrderId(id int64) string
- func CreateXls(filename string, titles []any, data [][]any) error
- func Daemon()
- func Date(fmt string, unix int64) string
- func Div(num1, num2, point int64) float64
- func ExcelDateToDate(excelDate string) time.Time
- func FloatStringToInt(str string, point float64) int64
- func GBK2UTF8(str []byte) ([]byte, error)
- func GetFreePort() (string, error)
- func GetPost(method string, sUrl string, data map[string]string, head map[string]string, ...) (string, error)
- func LocalIP() bool
- func LocalIPV4() string
- func Md5(in []byte) string
- func Md5File(filePath string) (string, error)
- func Mod(id int64) int64
- func ParseSimpleJson(jsonStr string) (map[string]string, error)
- func RandRangeInt(start, end int64) int64
- func ReadXls(filename string) ([][]string, error)
- func SetTimeZone(zoneStr string) error
- func Sha256(in []byte) string
- func SignPost(domain string, key string, secret string, control string, method string, ...) (string, error)
- func SingleFlight(ctx context.Context, key string, method func(context.Context) (any, error)) (any, error)
- func StampToTimeStamp(stamp int64, phpFormat string) int64
- func StrToTime(phpFormat string, timeStr string) (int64, error)
- func Time() int64
- func UTF82GBK(str []byte) ([]byte, error)
- func WriteFile(fileName string, content []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckCustomStructPtrExport ¶
CheckCustomStructPtrExport 检测自定义struct指针参数并且可导出
func ClientIP ¶
ClientIP 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。
func ComparePoint ¶
func ComparePoint[T comparable](t1, t2 T) bool
ComparePoint 比较数据是否相同 相同返回true
> - 布尔型、数值类型、字符串类型、指针类型和channel是严格可比较的。
> - 如果结构体类型的所有字段的类型都是严格可比较的,那么该结构体类型就是严格可比较的。
> - 如果数组元素的类型是严格可比较的,那么该数组类型就是严格可比较的。
> - 如果类型形参的类型集合中的所有类型都是严格可比较的,那么该类型形参就是严格可比较的。
func CreateOrderId ¶
func ExcelDateToDate ¶
ExcelDateToDate excel读取到的日期转换为time类型
func FloatStringToInt ¶
FloatStringToInt float类型的字符串转为整数 point 小数位数
func GetPost ¶
func GetPost(method string, sUrl string, data map[string]string, head map[string]string, cookie []*http.Cookie) (string, error)
GetPost 发送get 或 post请求 获取数据
func ParseSimpleJson ¶
ParseSimpleJson 解析简单json数据为map[string]string结构 参考格式:{"a":"b","c":123,"d":[1,2,3],"e":["h","i","j"]}
func SignPost ¶
func SignPost(domain string, key string, secret string, control string, method string, data map[string]string) (string, error)
SignPost 内部使用 请求参数加密验证 发送post请求到接口
func SingleFlight ¶
func SingleFlight(ctx context.Context, key string, method func(context.Context) (any, error)) (any, error)
SingleFlight 防止缓存击穿
适用场景: key的生成需要谨慎
1.单机模式下的生成缓存;如果分布式模式下,请使用其他方式
2.将多个请求合并成一个请求,比如post短时多次提交;get同一内容
eg: ret, err := cFunc.SingleFlight(context.Background(), key, jisuan)
eg: fmt.Println(ret.(int64), err)
eg: func jisuan(ctx context.Context) (any, error) {
eg: return time.Now().Unix(), nil
eg: }
func StampToTimeStamp ¶
StampToTimeStamp 将时间戳 按指定格式 转换为新的时间戳 stamp 时间戳 如果为0则处理为当前时间 仅支持最常用的 Y-m-d H:i:s 仅支持最常用的 Y-m-d
Types ¶
This section is empty.