utils

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PaddingTypePKCS7 = iota // 推荐使用
	PaddingTypePKCS5
	PaddingTypeZero      // 不推荐使用
	PaddingTypeNoPadding // 不要用
)
View Source
const HandlerName = "handlerName"
View Source
const INT32MAX = 4294967296
View Source
const MagicNum = 65521
View Source
const MagicNum2 = 65519
View Source
const NapiArticleCryptKey = "^.vAy$TT"
View Source
const NapiQuestionCryptKey = "iVPed<7K"
View Source
const QbQuestionCryptKey = "lVPed<8K"
View Source
const ZybChargeCryptKey = "^.vAy$TG"
View Source
const ZybLectureCryptKey = "*)<~0YZS"
View Source
const ZybOpenidCryptKey = "^.iC$eSC"
View Source
const ZybUidCryptKey = "^.vB>$TS"

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(encrypted, key []byte) ([]byte, error)

AesDecrypt Aes解密

func AesDecryptV2

func AesDecryptV2(crypted, key []byte) ([]byte, error)

AesDecryptV2 Aes解密

func AesEncrypt

func AesEncrypt(src, key string) ([]byte, error)

AesEncrypt Aes加密

func AesEncryptV2

func AesEncryptV2(src, key string) ([]byte, error)

AesEncryptV2 Aes加密

func Base64Decode

func Base64Decode(str string) (string, error)

func Base64Encode

func Base64Encode(str string) string

func Bin2hex

func Bin2hex(binStr string) string

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func CompareSortedStrings

func CompareSortedStrings(lhs, rhs []string) bool

比较已经排序好的字符串切片

func CompareVersion

func CompareVersion(ver1, ver2 string, ignoreCase ...bool) int

CompareVersion 版本比较 -1: ver1 < ver2 0: ver1 == ver2 1: ver1 > ver2

func Copy

func Copy(toValue interface{}, fromValue interface{}) (err error)

Copy copy things

func DecodeAQid

func DecodeAQid(qStr string) (qid int, err error)

func DecodeCid

func DecodeCid(qStr string) (qid int, err error)

func DecodeLid

func DecodeLid(qStr string) (qid int, err error)

func DecodeOuid

func DecodeOuid(qStr string) (qid int, err error)

func DecodeQid

func DecodeQid(qstr string, qType int) (qid int, err error)

func DecodeUid

func DecodeUid(qStr string) (qid int, err error)

func DecryptDesEcb

func DecryptDesEcb(src, key string, paddingType int) (d string, err error)

ECB解密, 使用PKCS7进行填充

func DeviceUUIDByMAC

func DeviceUUIDByMAC() string

func DiffStrings

func DiffStrings(oldStrings, newStrings []string) ([]string, []string)

return adds, dels

func DoZlibCompress

func DoZlibCompress(src []byte) ([]byte, error)

DoZlibCompress ZIP压缩数据

func DoZlibUnCompress

func DoZlibUnCompress(compressSrc []byte) ([]byte, error)

DoZlibUnCompress ZIP解压数据

func EncodeAQid

func EncodeAQid(qid int) (e string, err error)

func EncodeCid

func EncodeCid(qid int) (e string, err error)

func EncodeLid

func EncodeLid(qid int) (e string, err error)

func EncodeOuid

func EncodeOuid(qid int) (e string, err error)

func EncodeQid

func EncodeQid(qid, qType int) (e string, err error)

func EncodeUid

func EncodeUid(qid int) (e string, err error)

func EncryptDesEcb

func EncryptDesEcb(src, key string, paddingType int) (e string, err error)

ECB加密, 使用PKCS7进行填充

func Exists

func Exists(path string) bool

判断文件或目录是否存在

func FileSize

func FileSize(file string) (int64, error)

func Format

func Format(format string, t time.Time) string

Format 格式化时间 %Y-%m-%d %H:%I:%S This is an alternative to time.Format because no one knows what date 040305 is supposed to create when used as a 'layout' string this takes standard strftime format options. For a complete list of format options see http://strftime.org/

func FormatTimeByUnixSec

func FormatTimeByUnixSec(sec int64) string

func GenUUID

func GenUUID() string

获取 uuid

func GetClientIp

func GetClientIp(ctx context.Context) string

过 ingress 的请求clientIp 优先从 "X-Original-Forwarded-For" 中获取

func GetContextValue

func GetContextValue(ctx context.Context, key string) (value any)

func GetContextValueInt64

func GetContextValueInt64(ctx context.Context, key string) (value int64)

func GetContextValueString

func GetContextValueString(ctx context.Context, key string) (value string)

func GetFormatRequestTime

func GetFormatRequestTime(time time.Time) string

func GetFunctionName

func GetFunctionName(i interface{}, seps ...rune) string

获取函数名称

func GetHandler

func GetHandler(ctx context.Context) (handler string)

func GetLocalIPList

func GetLocalIPList() []string

GetLocalIPList 获取本机IP列表

func GetLocalIp

func GetLocalIp() string

GetLocalIp 获取本机第一个内网 ip

func GetLocalServerID

func GetLocalServerID() (string, error)

func GetMacAddr

func GetMacAddr() (macAddr string, err error)

GetMacAddr 获取机器MAC地址

func GetRequestCost

func GetRequestCost(start, end time.Time) float64

func GetUuidString

func GetUuidString() string

func GetUuidUInt64

func GetUuidUInt64() uint64

func Hex2bin

func Hex2bin(hexStr string) (string, error)

func InitUnCompress

func InitUnCompress(sourceReader io.Reader) (obj *unCompress)

func Int64SliceToString

func Int64SliceToString(s []int64, sepF ...string) string

func Int64sContain

func Int64sContain(a []int64, x int64) bool

func IntStringContain

func IntStringContain(a []string, x string) bool

func IsExist

func IsExist(path string) bool

func IsJsonMap

func IsJsonMap(s string) bool

func IsJsonSlice

func IsJsonSlice(s string) bool

func IsJsonString

func IsJsonString(s string) bool

func IsStringNotEmpty

func IsStringNotEmpty(str ...string) bool

func JoinArgs

func JoinArgs(showByte int, args ...interface{}) string

func LoadConf

func LoadConf(path string, cf interface{}) bool

func LoadFile

func LoadFile(path string) ([]byte, bool)

func Md5

func Md5(plain string) string

单向加密算法

func MultiJoinString

func MultiJoinString(str ...string) string

func NewMail

func NewMail() *mail

NewMail 构造新邮件实例

NewMail().Server(host, port).Auth(username, password).Timeout(5*time.Second).WithTLS().WithHTML().Content(subject, content).Send(sendto, from)
构造实例 -> 服务器信息 -> 用户认证信息 -> 设置连接超时(optional) -> 启用SSL(optional) -> 使用text/html(optional) -> 填写邮件内容 -> 投递邮件

func PKCS5Padding

func PKCS5Padding(cipherText []byte) []byte

PKCS7Padding的子集,块大小固定为8字节

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func PKCS7Padding

func PKCS7Padding(cipherText []byte, blockSize int) []byte

假设数据长度需要填充n(n>0)个字节才对齐,那么填充n个字节,每个字节都是n; 如果数据本身就已经对齐了,则填充一块长度为块大小的数据,每个字节都是块大小

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

func RandNum

func RandNum(num ...int) int

func Rc4Decode

func Rc4Decode(key, encrypted string) (string, error)

func Rc4DecodeBytes

func Rc4DecodeBytes(key []byte, encrypted string) ([]byte, error)

func Rc4Encode

func Rc4Encode(key, plainText string) (string, error)

func Rc4EncodeBytes

func Rc4EncodeBytes(key, plainText []byte) (string, error)

func SHA1

func SHA1()

func SHA256

func SHA256()

func SaveConf

func SaveConf(conf interface{}, path string) bool

func SetContextValue

func SetContextValue(ctx context.Context, key string, value any) context.Context

SetContextValue 上下文设置值 注意!如果是go默认的上下文,则需要重建ctx,注意接收,否则不生效

func StrToUint

func StrToUint(strNumber string, value interface{}) error

func StringToBytes

func StringToBytes(s string) (b []byte)

StringToBytes converts string to byte slice without a memory allocation.

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

func UnmarshalJson

func UnmarshalJson(jsonVal []byte, objVal interface{}) error

func Xor

func Xor(arr []byte)

Xor encrypt by xor

func ZeroPadding

func ZeroPadding(cipherText []byte, blockSize int) []byte

ZeroPadding,数据长度不对齐时使用0填充,否则不填充 只适合以\0结尾的字符串加解密

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

Types

type BufferPool

type BufferPool struct {
	sync.Pool
}

func NewBufferPool

func NewBufferPool(bufferSize int) (bufferpool *BufferPool)

声明一块buffer pool大小

func (*BufferPool) Get

func (bufferpool *BufferPool) Get() *bytes.Buffer

获取一块buffer写入

func (*BufferPool) Put

func (bufferpool *BufferPool) Put(b *bytes.Buffer)

放回buffer重用

type Conf

type Conf struct {
	*viper.Viper
	Name string
	Data interface{}
}

func Load

func Load(name string, data interface{}) (*Conf, error)

func (*Conf) Sub

func (conf *Conf) Sub(key string) *Conf

type MailContact

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

MailContact 邮件联系人

func NewMailContact

func NewMailContact(name, email string) *MailContact

func (*MailContact) String

func (c *MailContact) String() string

String 将邮件联系人结构转写为邮件内容格式

Directories

Path Synopsis
extend
generics
generics

Jump to

Keyboard shortcuts

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