util

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodePassword

func EncodePassword[PK any](original []byte, key PK) (success bool, result []byte)

EncodePassword 使用crypto/scrypt密钥库对密码进行单向加密

func EncodeRandomSalt

func EncodeRandomSalt[PK any](key PK) []byte

EncodeRandomSalt 对任意类型的key进行编码生成一个长度为8的[]byte结果

func Error

func Error(chan error)

func GenerateHash

func GenerateHash[Key any](key Key) (hash uint)

GenerateHash 将任意结构进行哈希,使用SDBM算法作为实现

func GenerateHashWithOpts

func GenerateHashWithOpts[Key any, Hash UintLike](key Key) (hash Hash)

GenerateHashWithOpts 将任意结构进行哈希,生成一个指定类型(无符号整形)的哈希值,使用SDBM算法作为实现

func GenerateMD5

func GenerateMD5(source string) (md5CheckSum string)

GenerateMD5 将给定的字符串使用MD5摘要算法生成摘要

func GeneratePackageID

func GeneratePackageID[ID UintLike](packageName string) (id ID)

GeneratePackageID 根据给定的包名,生成其Hash,不保证不会冲突

func GeneratePrefixHash

func GeneratePrefixHash[Key any](key Key, offset uintptr) (hash uint)

GeneratePrefixHash 将任意结构的前offset字节的内容进行哈希,越界部份不会被计算,使用SDBM算法作为实现

func GeneratePrefixHashWithOpts

func GeneratePrefixHashWithOpts[Key any, Hash UintLike](key Key, offset uintptr) (hash Hash)

GeneratePrefixHashWithOpts 将任意结构的前offset字节的内容进行哈希,生成一个指定类型(无符号整形)的哈希值,越界部份不会被计算,使用SDBM算法作为实现

func GenerateRealID

func GenerateRealID(uid uint64, sub uint16) (realID uint64)

GenerateRealID 根据MOD的ID和MOD中的ID,拼接出真实ID

func GenerateTypeID

func GenerateTypeID[T any](entity T) (uid string)

GenerateTypeID 根据entity的包和结构名,生成类型ID

func GenerateUID

func GenerateUID(mac uint64, timeStamp time.Time) (uid uint64)

GenerateUID 根据时间戳生成一个UID,毫秒级,48位,其中前6位为设备序列号,后42位为毫秒时间戳,可使用138年

func GenerateUUID

func GenerateUUID() string

GenerateUUID 生成一个UUID,长度为36

func GetMacAddresses

func GetMacAddresses() (macAddr []net.Interface, err error)

GetMacAddresses 使用net包获取本机mac地址

func GetUintMacAddress

func GetUintMacAddress(mac net.Interface) (addr uint64, err error)

GetUintMacAddress 从net.Interface中获取一个uint64类型的地址,长度为48位

func GetZeroTimeStamp

func GetZeroTimeStamp() time.Time

GetZeroTimeStamp 获取系统的零时

func Info

func Info(chan interface{})

func Trace

func Trace(chan interface{})

Types

type ErrorHandler

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

func (*ErrorHandler) Handle

func (e *ErrorHandler) Handle(err error)

type InfoLogger

type InfoLogger struct{}

type SystemBits

type SystemBits byte
const (
	BitsUnknown SystemBits = 0
	Bits32      SystemBits = 32
	Bits64      SystemBits = 64
)

func GetSystemBits

func GetSystemBits() SystemBits

GetSystemBits 获取操作系统的位数,结果为SystemBits

type TraceLogger

type TraceLogger struct{}

type UintLike

type UintLike interface {
	uint | uint8 | uint16 | uint32 | uint64
}

Jump to

Keyboard shortcuts

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