utils

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const KEY = "fakeKeyChangeMe!"

KEY 密钥

Variables

This section is empty.

Functions

func AesDecode

func AesDecode(encryptedString, key string) (string, error)

AesDecode aes解密

使用CFB

key应该是一个16或24或32位长度的字符

func AesEncode

func AesEncode(rawString, key string) (string, error)

AesEncode aes加密

使用CFB

key应该是一个16或24或32位长度的字符

func Base64Decode

func Base64Decode(encodedString string) ([]byte, error)

Base64Decode base64解码

func Base64Encode

func Base64Encode(rawBytes []byte) string

Base64Encode base64编码

func FileAppendContents

func FileAppendContents(content []byte, dst string) error

FileAppendContents 将内容写入文件(追加写)

content []byte 写入的内容

dst string 写入的目标地址

func FileExists

func FileExists(dst string) bool

FileExists 检查文件上是否存在

dst string 目标地址

func FileExistsWithError

func FileExistsWithError(dst string) (bool, error)

FileExistsWithError 检查文件上是否存在(会返回错误信息)

dst string 目标地址

func FileExt

func FileExt(filename string) string

FileExt 获取文件扩展名

根据文件名最后一个.分隔来切分获取

func FileGetContents

func FileGetContents(filename string) ([]byte, error)

FileGetContents 获取文件内容

filename string 文件地址

func FileGetContentsReadLine

func FileGetContentsReadLine(dst string) (<-chan string, error)

FileGetContentsReadLine 逐行读取文件内容

func FilePutContents

func FilePutContents(content []byte, dst string) error

FilePutContents 将内容写入文件(覆盖写)

content []byte 写入的内容

dst string 写入的目标地址

func GenerateVAPIDKeys added in v2.0.2

func GenerateVAPIDKeys() (privateKey string, publicKey string, err error)

GenerateVAPIDKeys 生成web push的公私钥

func GetLocalIP

func GetLocalIP() (string, error)

func ListeningExitSignal

func ListeningExitSignal(wg *sync.WaitGroup)

ListeningExitSignal 监听系统退出信号

func RSADecrypt

func RSADecrypt(encodedString string, privateKey []byte) (string, error)

RSADecrypt rsa解密

func RSAEncrypt

func RSAEncrypt(rawString string, publicKey []byte) (string, error)

RSAEncrypt rsa加密

func RSASign

func RSASign(rawStringBytes, privateKey []byte) (string, error)

RSASign rsa加签

func RSAVerifySign

func RSAVerifySign(rawStringBytes, sign, publicKey []byte) (bool, error)

RSAVerifySign rsa验签

func RandomDigitalChars

func RandomDigitalChars(length int) string

RandomDigitalChars 随机字符串(数字)

func RandomLetters

func RandomLetters(length int) string

RandomLetters 随机字符串(字母)

func RedisClusterLock added in v2.0.2

func RedisClusterLock(key string) bool

RedisClusterLock redis锁-上锁(使用cluster)

using SetNX

func RedisClusterUnlock added in v2.0.2

func RedisClusterUnlock(key string)

RedisClusterUnlock redis锁-解锁(使用cluster)

using SetNX

func RedisLock added in v2.0.2

func RedisLock(key string) bool

RedisLock redis锁-上锁

using SetNX

func RedisUnlock added in v2.0.2

func RedisUnlock(key string)

RedisUnlock redis锁-解锁

using SetNX

func SaveFile2Dst

func SaveFile2Dst(file *multipart.FileHeader, dst string) error

SaveFile2Dst 将文件保存到目标地址(拷贝文件)

file *multipart.FileHeader 文件

dst string 拷贝到的目标地址

func SendNotification added in v2.0.2

func SendNotification(privateKey, publicKey string, sub webpush.Subscription, subscriberEmail string, body Payload) error

SendNotification 发送通知

func ValidateEmail added in v2.0.2

func ValidateEmail(email string) bool

ValidateEmail 验证邮箱格式

func Wordwrap

func Wordwrap(rawStr string, length int, split string) string

Wordwrap 以给定的字符和长度来打断字符串

func WrapRedisKey

func WrapRedisKey(appName, key string) string

WrapRedisKey 包装redis键名

给redis的键加入应用名前缀,如:

appName=game key=user

最终的redis键名为:game:user

此方法的主要作用是按应用来划分redis键名

Types

type Payload added in v2.0.2

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 added in v2.0.2

type PayloadDataField struct {
	URL string `json:"url"`
}

PayloadDataField 消息推送载荷-data字段

type TIM

type TIM struct {
	// contains filtered or unexported fields
}

func NewTimeWithTimeZone

func NewTimeWithTimeZone(timeZone ...string) *TIM

NewTimeWithTimeZone 根据时区初始化时间

默认时区: Asia/Shanghai

func (*TIM) Date

func (t *TIM) Date() string

func (*TIM) Datetime

func (t *TIM) Datetime() string

func (*TIM) Now

func (t *TIM) Now() time.Time

func (*TIM) Time

func (t *TIM) Time() string

Jump to

Keyboard shortcuts

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