cFunc

package
v1.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

README

公共基础函数

  • md5加密
  • 编码转换
  • 追加写入文件 便于调试
  • 获取IP
  • 判断本地IP是否内网【局限于常用环境】
  • 对数字求mod值
  • 获取一个可用的端口号

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BreakSensitive added in v1.1.4

func BreakSensitive(str string, frontLen int, behindLen int) string

BreakSensitive 对铭感字符串脱敏处理

func Bytes2String added in v1.1.4

func Bytes2String(b []byte) string

func CheckCustomStructPtrExport

func CheckCustomStructPtrExport(dataPtr any) error

CheckCustomStructPtrExport 检测自定义struct指针参数并且可导出

func CheckMobile

func CheckMobile(mobile string) bool

CheckMobile 校验手机号码

func ClientIP

func ClientIP(r *http.Request) string

ClientIP 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func ComparePoint

func ComparePoint[T comparable](t1, t2 T) bool

ComparePoint 比较数据是否相同 相同返回true

> - 布尔型、数值类型、字符串类型、指针类型和channel是严格可比较的。

> - 如果结构体类型的所有字段的类型都是严格可比较的,那么该结构体类型就是严格可比较的。

> - 如果数组元素的类型是严格可比较的,那么该数组类型就是严格可比较的。

> - 如果类型形参的类型集合中的所有类型都是严格可比较的,那么该类型形参就是严格可比较的。

func ConvertStr

func ConvertStr(col string) string

ConvertStr 将数据库中的表字段 转换为go中使用的名称

func CreateOrderId

func CreateOrderId(id int64) string

func Daemon

func Daemon()

Daemon 将进程放入后台执行

func Date

func Date(fmt string, unix int64) string

Date 返回格式化后的时间字符串 format 支持PHP的时间格式 unix 时间戳默认为当前时间

func Div

func Div(num1, num2, point int64) float64

Div 计算除法 保留小数位数

func FloatStringToInt

func FloatStringToInt(str string, point float64) int64

FloatStringToInt float类型的字符串转为整数 point 小数位数

func Fnv32a added in v1.1.4

func Fnv32a(str string) uint32

Fnv32a 计算字符串的hash值,将字符串转成整形

func GBK2UTF8

func GBK2UTF8(str []byte) ([]byte, error)

GBK2UTF8 gbk编码 转 utf8编码

func GetFreePort

func GetFreePort() (string, error)

GetFreePort 获取一个可用的端口号

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 HashShard added in v1.1.4

func HashShard(str string, shardCount int) int

HashShard 求字符串的hash值分片数 @param shardCount 分配总数

func JsonMarshalDisEscape added in v1.1.8

func JsonMarshalDisEscape(data any) ([]byte, error)

JsonMarshalDisEscape json.Marshal禁用转义 系统内默认为转义特殊字符

func LocalIP

func LocalIP() bool

LocalIP 判断是否为本地局域网/内网ip

func LocalIPV4

func LocalIPV4() string

LocalIPV4 获取本地IPv4地址

func Md5

func Md5(in []byte) string

func Md5File

func Md5File(filePath string) (string, error)

Md5File 计算文件的md5值

func MemStats added in v1.1.7

func MemStats() string

MemStats 返回内存占用状态

func Mod

func Mod(id int64) int64

Mod 给数据库分表等计算

func ParseJsonArrayObject added in v1.1.6

func ParseJsonArrayObject(str []byte) ([][]byte, error)

ParseJsonArrayObject 解析json数组对象到 [][]byte 内部对象可继续交给 ParseSimpleJson 解析

func ParseSimpleJson

func ParseSimpleJson(jsonByte *[]byte) (map[string]string, error)

ParseSimpleJson 解析简单json数据为map[string]string结构 参考格式:{"a":"b","c":123,"d":[1,2,3],"e":["h","i","j"]} 参考格式:{"a":"b,c","c":123,"d":[1,2,3],"e":["h","i","j"]} 参考格式:{"role_id":165, "auto_operation":"{\"abc\":21212}"} 因为需要支持多层json 所以此方法不处理json中的特殊字符 比如\n \r \t等 [需在使用时自己替换] 转换后会破坏json数据结构 strings.ReplaceAll(value, "\\n", "\n")

func RandInt added in v1.1.4

func RandInt(max uint64) uint64

RandInt 生成随机数[0 - max)

func RandRangeInt

func RandRangeInt(start, end uint64) int64

RandRangeInt 生成随机数[n - m)

func SetTimeZone

func SetTimeZone(zoneStr string) error

SetTimeZone 全局修改该包的时区

func Sha256

func Sha256(in []byte) string

func Sha256File added in v1.1.4

func Sha256File(filePath string) (string, error)

func SignPost

func SignPost(domain string, key string, secret string, control string, method string, data map[string]string) (string, error)

SignPost 内部使用 请求参数加密验证 发送post请求到接口

func StampToTimeStamp

func StampToTimeStamp(stamp int64, phpFormat string) int64

StampToTimeStamp 将时间戳 按指定格式 转换为新的时间戳 stamp 时间戳 如果为0则处理为当前时间 仅支持最常用的 Y-m-d H:i:s 仅支持最常用的 Y-m-d

func StrToTime

func StrToTime(phpFormat string, timeStr string) (int64, error)

StrToTime 将时间字符串 转换为 时间戳 将时间戳 转换为 指定时间格式 对应的 时间戳 仅支持最常用的 Y-m-d H:i:s 和 Y-m-d stamp 时间戳 如果为0则处理为当前时间

func String2Bytes added in v1.1.4

func String2Bytes(s string) []byte

func Time

func Time() int64

Time 返回时间戳

func UTF82GBK

func UTF82GBK(str []byte) ([]byte, error)

UTF82GBK utf8编码 转 gbk编码

func WriteFile

func WriteFile(fileName string, content []byte) error

WriteFile 追加写入文件内容 如果fileName为绝对路径则直接使用 如果为相对路径则获取当前程序路径

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL