utils

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitClear

func BitClear[T Int](val T, position int) T

BitClear 清理设置某一位的数值为0,从右到左方向

func BitSet

func BitSet[T Int](val T, position int) T

BitSet 填充设置某一位的数值为1,从右到左方向

func Equal

func Equal(obj any, target any, targets ...any) bool

Equal 判断target跟targets内的所有项与val是否相等,如果全部target都与val相等 如果obj与target跟targets里面的所有数据都相等,则返回true,如果有其中一项不相等,则返回false

func FormatGroupRoomID

func FormatGroupRoomID(groupID int64) string

FormatGroupRoomID 格式化群组聊天室房间号

func FormatPrivateRoomID

func FormatPrivateRoomID(userAID, userBID int64) string

FormatPrivateRoomID 格式化私人聊天室房间号

func FormatWorldRoomID added in v1.0.3

func FormatWorldRoomID(worldID int64) string

FormatWorldRoomID 格式化世界聊天室房间号

func GetClientIP

func GetClientIP(r *http.Request) (string, error)

GetClientIP 获取用户的真实IP

func GetHostname added in v1.0.5

func GetHostname() string

GetHostname 获取本机名

func GetLocalIP added in v1.0.5

func GetLocalIP() string

GetLocalIP 获取本机IP地址

func GetLocalIPs added in v1.0.5

func GetLocalIPs() []string

func In

func In(obj any, target any, targets ...any) bool

In 判断obj是否与target或者targets内的某个元素相等 如果 obj 等于 target 或者等于 targets 其中一项,则返回true 如果没匹配到其中一项,则返回false

func IntBetween

func IntBetween[T Int](dest, from, to T) bool

IntBetween dest在指定范围内 是一个闭区间 from <= dest <= to

func IntLen

func IntLen[T Int](val T) int

func IsNil added in v1.0.4

func IsNil(v any) bool

IsNil 检测是否是真nil值

func MD5

func MD5(src []byte) []byte

MD5 封装的一个MD5加密字节组

func MD5String

func MD5String(src string) string

MD5String 封装的一个MD5加密字符串的方法

func PasswordHash

func PasswordHash(pwd string) string

PasswordHash 封装的一个哈希密码的加密方法 使用双重MD5进行加密

func SliceUnique

func SliceUnique(data any, dst any) error

SliceUnique 将切片进行唯一归类

func SortInt

func SortInt[T Int](a T, b T) (T, T)

SortInt 排序整型 返回的数据总是 a < b

func StringCut

func StringCut(data string, limit int) string

StringCut 裁剪字符串

func StringLen

func StringLen(data string) int

StringLen 返回字符串的长度,因为中文需要3个字节(byte),所以,我们使用rune来代替

func UUID added in v1.0.3

func UUID() string

UUID 全球唯一标识

Types

type Int

type Int interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Int 整型的一个泛型 包括 ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64

Jump to

Keyboard shortcuts

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