Documentation ¶
Index ¶
- Constants
- func AesDecode(encryptedString, key string) (string, error)
- func AesEncode(rawString, key string) (string, error)
- func Base64Decode(encodedString string) ([]byte, error)
- func Base64Encode(rawBytes []byte) string
- func CharCodeAt(character string) rune
- func Crc32Checksum(data []byte, table *crc32.Table) uint32
- func Crc32ChecksumIEEE(data []byte) uint32
- func Crc64Checksum(data []byte, table *crc64.Table) uint64
- func Crc64ChecksumECMA(data []byte) uint64
- func FileAppendContents(content []byte, dst string) error
- func FileExists(dst string) bool
- func FileExistsWithError(dst string) (bool, error)
- func FileExt(filename string) string
- func FileGetContents(filename string) ([]byte, error)
- func FileGetContentsReadLine(dst string) (<-chan string, error)
- func FilePutContents(content []byte, dst string) error
- func FormatDate(date time.Time, dateStyle DateStyle) string
- func FromCharCode(code int32) string
- func GenerateVAPIDKeys() (privateKey string, publicKey string, err error)
- func GetLocalIP() (string, error)
- func ListeningExitSignal(wg *sync.WaitGroup)
- func MD5Encode(rawString string) string
- func ParseDate(date, layout string, loc *time.Location) (time.Time, error)
- func PrintSwaggerControllerInfo(param SwaggerControllerInfoParam) string
- func PrintSwaggerSummaryInfo(param SwaggerSummaryInfoParam) string
- func PrintVersion(fields VersionInfoFields)
- func RSADecrypt(encodedString string, privateKey []byte) (string, error)
- func RSAEncrypt(rawString string, publicKey []byte) (string, error)
- func RSASign(rawStringBytes, privateKey []byte) (string, error)
- func RSAVerifySign(rawStringBytes, sign, publicKey []byte) (bool, error)
- func RandomComplexString(length int) string
- func RandomDigitalChars(length int) string
- func RandomLetters(length int) string
- func RandomString(length int) string
- func RedisClusterLock(key string) bool
- func RedisClusterLockWithContext(ctx context.Context, key string) bool
- func RedisClusterUnlock(key string)
- func RedisClusterUnlockWithContext(ctx context.Context, key string)
- func RedisLock(ctx context.Context, key string)
- func RedisStandaloneLock(key string) bool
- func RedisStandaloneLockWithContext(ctx context.Context, key string) bool
- func RedisStandaloneUnlock(key string)
- func RedisStandaloneUnlockWithContext(ctx context.Context, key string)
- func RedisTryLock(key string) bool
- func RedisTryLockWithContext(ctx context.Context, key string) bool
- func RedisUnlock(key string)
- func RedisUnlockWithContext(ctx context.Context, key string)
- func SM4ECBDecrypt(hexKey, base64Raw string) (string, error)
- func SM4ECBEncrypt(hexKey, raw string) (string, error)
- func SaveFile2Dst(file *multipart.FileHeader, dst string) error
- func SendNotification(privateKey, publicKey string, sub webpush.Subscription, subscriberEmail string, ...) error
- func StringPaddingBoth(rawString, padChar string, length int) string
- func StringPaddingLeft(rawString, padChar string, length int) string
- func StringPaddingRight(rawString, padChar string, length int) string
- func StringReverse(s string) string
- func StringShuffle(s string) string
- func ValidateEmail(email string) bool
- func ValidateIdentityCard(idCard string) bool
- func Wordwrap(rawStr string, length int, split string) string
- func WrapRedisKey(appName, key string) string
- type CancelFunc
- type DateStyle
- type HeapHelper
- type HeapStd
- type IAnyValue
- type Payload
- type PayloadDataField
- type SwaggerControllerInfoParam
- type SwaggerSummaryInfoParam
- type TIM
- type VersionInfoFields
Constants ¶
const ( MM_DD = "MM-dd" YYYYMM = "yyyyMM" YYYY_MM = "yyyy-MM" YYYY_MM_DD = "yyyy-MM-dd" YYYYMMDD = "yyyyMMdd" YYYYMMDDHHMMSS = "yyyyMMddHHmmss" YYYYMMDDHHMM = "yyyyMMddHHmm" YYYYMMDDHH = "yyyyMMddHH" YYMMDDHHMM = "yyMMddHHmm" MM_DD_HH_MM = "MM-dd HH:mm" MM_DD_HH_MM_SS = "MM-dd HH:mm:ss" YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm" YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss" YYYY_MM_DD_HH_MM_SS_SSS = "yyyy-MM-dd HH:mm:ss.SSS" MM_DD_EN = "MM/dd" YYYY_MM_EN = "yyyy/MM" YYYY_MM_DD_EN = "yyyy/MM/dd" MM_DD_HH_MM_EN = "MM/dd HH:mm" MM_DD_HH_MM_SS_EN = "MM/dd HH:mm:ss" YYYY_MM_DD_HH_MM_EN = "yyyy/MM/dd HH:mm" YYYY_MM_DD_HH_MM_SS_EN = "yyyy/MM/dd HH:mm:ss" YYYY_MM_DD_HH_MM_SS_SSS_EN = "yyyy/MM/dd HH:mm:ss.SSS" MM_DD_CN = "MM月dd日" YYYY_MM_CN = "yyyy年MM月" YYYY_MM_DD_CN = "yyyy年MM月dd日" MM_DD_HH_MM_CN = "MM月dd日 HH:mm" MM_DD_HH_MM_SS_CN = "MM月dd日 HH:mm:ss" YYYY_MM_DD_HH_MM_CN = "yyyy年MM月dd日 HH:mm" YYYY_MM_DD_HH_MM_SS_CN = "yyyy年MM月dd日 HH:mm:ss" HH_MM = "HH:mm" HH_MM_SS = "HH:mm:ss" HH_MM_SS_MS = "HH:mm:ss.SSS" )
const KEY = "fakeKeyChangeMe!"
KEY 密钥
Variables ¶
This section is empty.
Functions ¶
func Crc32Checksum ¶ added in v3.0.2
Crc32Checksum 求crc32校验码
func Crc64Checksum ¶ added in v3.0.2
Crc64Checksum 求crc64校验码
func FileGetContentsReadLine ¶
FileGetContentsReadLine 逐行读取文件内容
func FormatDate ¶ added in v3.0.1
FormatDate 时间对象转字符串
func FromCharCode ¶ added in v3.0.4
FromCharCode 返回ASCII码对应的字符
Note ¶
常规ASCII码表范围为0~127
扩展ASCII码表范围为128~255
func GenerateVAPIDKeys ¶
GenerateVAPIDKeys 生成web push的公私钥
func ListeningExitSignal ¶
ListeningExitSignal 监听系统退出信号
func PrintSwaggerControllerInfo ¶
func PrintSwaggerControllerInfo(param SwaggerControllerInfoParam) string
PrintSwaggerControllerInfo 打印swagger控制器信息
用于生成swagger注释
func PrintSwaggerSummaryInfo ¶
func PrintSwaggerSummaryInfo(param SwaggerSummaryInfoParam) string
PrintSwaggerSummaryInfo 打印swagger概览信息参数
用于生成swagger注释
func PrintVersion ¶ added in v3.0.1
func PrintVersion(fields VersionInfoFields)
func RSADecrypt ¶
RSADecrypt rsa解密
func RSAEncrypt ¶
RSAEncrypt rsa加密
func RSAVerifySign ¶
RSAVerifySign rsa验签
func RandomComplexString ¶ added in v3.0.2
RandomComplexString 随机字符串(可带特殊符号)
func RedisClusterLockWithContext ¶ added in v3.0.4
RedisClusterLockWithContext redis锁-上锁(使用cluster)
using SetNX
func RedisClusterUnlock ¶
func RedisClusterUnlock(key string)
RedisClusterUnlock redis锁-解锁(使用cluster)
using SetNX
func RedisClusterUnlockWithContext ¶ added in v3.0.4
RedisClusterUnlockWithContext redis锁-解锁(使用cluster)
using SetNX
func RedisLock ¶
RedisLock redis锁-上锁(自动推测连接类型)
using SetNX
与之对应的是使用 RedisUnlock 解锁
Note ¶
该方法会阻塞住线程直到上锁成功 或者 触发ctx.Done()
func RedisStandaloneLockWithContext ¶ added in v3.0.4
RedisStandaloneLockWithContext redis锁-上锁(使用standalone)
using SetNX
func RedisStandaloneUnlock ¶ added in v3.0.1
func RedisStandaloneUnlock(key string)
RedisStandaloneUnlock redis锁-解锁(使用standalone)
using SetNX
func RedisStandaloneUnlockWithContext ¶ added in v3.0.4
RedisStandaloneUnlockWithContext redis锁-解锁(使用standalone)
using SetNX
func RedisTryLock ¶ added in v3.0.2
RedisTryLock redis锁-尝试上锁(自动推测连接类型)
using SetNX
与之对应的是使用 RedisUnlock 解锁
Note ¶
该方法会立即返回锁定成功与否的结果
func RedisTryLockWithContext ¶ added in v3.0.4
RedisTryLockWithContext redis锁-尝试上锁(自动推测连接类型)
using SetNX
与之对应的是使用 RedisUnlock 解锁
Note ¶
该方法会立即返回锁定成功与否的结果
func RedisUnlockWithContext ¶ added in v3.0.4
RedisUnlockWithContext redis锁-解锁(自动推测连接类型)
using SetNX
func SM4ECBDecrypt ¶ added in v3.0.1
SM4ECBDecrypt ECB解密 hexKey 16进制key 长度32位 base64Raw 加密内容 base64格式
func SM4ECBEncrypt ¶ added in v3.0.1
SM4ECBEncrypt ECB加密 hexKey 16进制key 长度32位 raw 待加密内容
func SaveFile2Dst ¶
func SaveFile2Dst(file *multipart.FileHeader, dst string) error
SaveFile2Dst 将文件保存到目标地址(拷贝文件)
file *multipart.FileHeader 文件
dst string 拷贝到的目标地址
func SendNotification ¶
func SendNotification(privateKey, publicKey string, sub webpush.Subscription, subscriberEmail string, body Payload) error
SendNotification 发送通知
func StringPaddingBoth ¶ added in v3.0.2
StringPaddingBoth 向两端填充字符串
rawString 原字符
padChar 填充字符
length 最终字符长度
Note ¶
如果填充长度不能均分,那么右侧多填充一个字符,如:
rawString = "a",padChar = "#",length = 4
则:
result = "#a##"
func StringPaddingLeft ¶ added in v3.0.2
StringPaddingLeft 向左填充字符串
rawString 原字符
padChar 填充字符
length 最终字符长度
func StringPaddingRight ¶ added in v3.0.2
StringPaddingRight 向右填充字符串
rawString 原字符
padChar 填充字符
length 最终字符长度
func ValidateIdentityCard ¶ added in v3.0.1
ValidateIdentityCard (中国大陆)身份证格式校验 计算规则参考“中国国家标准化管理委员会” 官方文档@see http://www.gb688.cn/bzgk/gb/newGbInfo?hcno=080D6FBF2BB468F9007657F26D60013E
func WrapRedisKey ¶
WrapRedisKey 包装redis键名
给redis的键加入应用名前缀,如:
appName=game key=user
最终的redis键名为:game:user
此方法的主要作用是按应用来划分redis键名
Types ¶
type CancelFunc ¶ added in v3.0.2
type CancelFunc func()
type HeapHelper ¶ added in v3.0.4
type HeapHelper interface { // Push 将数据添加到堆中 Push(value IAnyValue) // Pop 将数据从堆中取出 Pop() IAnyValue }
func NewHeap ¶ added in v3.0.4
func NewHeap() HeapHelper
NewHeap 初始化一个全新的堆
它的作用是可以对任意数据类型的切片进行排序
实现 IAnyValue.SortByAsc 方法可以指定排序规则(升序、降序)
IAnyValue.GetScore 方法是排序的数值依据
type IAnyValue ¶ added in v3.0.4
type IAnyValue interface { // GetScore 获取对比分值 GetScore() float64 // SortByAsc 指定排序规则 // // true 为升序(小顶堆) // // false 为降序(大顶堆) SortByAsc() bool }
IAnyValue 任意值接口
type Payload ¶
type Payload struct { Title string `json:"title"` Body string `json:"body"` Icon string `json:"icon"` Data PayloadDataField `json:"data"` Badge string `json:"badge"` }
Payload 消息推送载荷
type PayloadDataField ¶
type PayloadDataField struct {
URL string `json:"url"`
}
PayloadDataField 消息推送载荷-data字段
type SwaggerControllerInfoParam ¶
type SwaggerControllerInfoParam struct { FunctionName string //方法名称 FunctionDesc string //方法描述 Tag string //分类标签 Summary string //简要标题 Description string //接口描述 Method string //请求方法 RequestParamString string //请求参数字符 ResponseBodyString string //返回体字符 ApiPath string //接口路径 NeedAuthorize bool //是否需要授权 }
SwaggerControllerInfoParam 控制器信息参数
type SwaggerSummaryInfoParam ¶
type SwaggerSummaryInfoParam struct { Title string //标题 Version string //版本 Description string //描述 TermOfServiceUrl string //服务条款地址 ContactName string //联系人 ContactUrl string //联系网址 ContactEmail string //联系邮箱 LicenseUrl string //证书网址 Host string //接口主机地址 BasePath string //接口公共前缀路径 NeedAuthorize bool //是否需要token授权 }
SwaggerSummaryInfoParam 概览信息参数
type TIM ¶
type TIM struct {
// contains filtered or unexported fields
}
func (*TIM) DatetimeTZ ¶ added in v3.0.4
DatetimeTZ 获取格式化后的当前日期时间-tz