util

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	APP_NAME string = "console-core-go"
)

Functions

func AcceptEmptyStringPtr

func AcceptEmptyStringPtr(str *string) string

func BToU

func BToU(b bool) uint8

func BsonId

func BsonId() string

func DeleteElemFromSlice

func DeleteElemFromSlice[T string | int | primitive.ObjectID](a []T, elem T) []T

func GenID

func GenID() (id string, err error)

func GetImageBase64

func GetImageBase64(logoPath string, bytes []byte) *string

func GetMachineId added in v0.0.4

func GetMachineId() (string, error)

func GetProtectedMachineId added in v0.0.4

func GetProtectedMachineId() (string, error)

func GetRequestScheme

func GetRequestScheme(c *gin.Context) string

websocket TODO Upgrade: websocket Connection: ...Upgrade...

func GetUserAgent

func GetUserAgent(c *gin.Context) string

func InterfaceToFloat64

func InterfaceToFloat64(t1 any) float64

interface{} -> float64

func InterfaceToInt

func InterfaceToInt(t1 any) int

interface{} -> int

func InterfaceToInt64

func InterfaceToInt64(t1 any) int64

interface{} -> int64

func InterfaceToString

func InterfaceToString(t1 any) string

func InterfaceToStruct

func InterfaceToStruct[T any](a any) (*T, error)

func InterfaceToUInt64

func InterfaceToUInt64(t1 any) uint64

interface{} -> uint64

func IsHttp

func IsHttp(c *gin.Context) bool

func IsHttps

func IsHttps(c *gin.Context) bool

func IsSSL

func IsSSL(c *gin.Context) bool

func IsStringEmpty

func IsStringEmpty(str *string) bool

func LCFirst

func LCFirst(str string) string

lower case first character, name according to php lcfirst

func NanoId

func NanoId() (id string, err error)

func RandString

func RandString(n uint8) string

func RandStringUpper

func RandStringUpper(n uint8) string

random string with upper case

func RejectEmptyString

func RejectEmptyString(str string) *string

func RejectEmptyStringPtr

func RejectEmptyStringPtr(str *string) *string

func SetDefault

func SetDefault[T interface{}](obj *T)

load default value from struct tag "default"

func SetIfNotEmpty

func SetIfNotEmpty(target *string, source *string)

func SetIfNotEq

func SetIfNotEq[T string | bool | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64](d *T, s *T)

byte = uint8

func SetIfNotNil

func SetIfNotNil[T interface{}](d *T, s *T)

func SetIfSourceNotEmpty

func SetIfSourceNotEmpty(target *string, source *string)

func SetIfSourceNotEmptyInt

func SetIfSourceNotEmptyInt(target *int, source *int)

func SliceRemoveDuplicate

func SliceRemoveDuplicate[T int | string | primitive.ObjectID](slc []T) []T

func String

func String(s string) *string

func StringTrim

func StringTrim(str *string) *string

func ToLowerFirst

func ToLowerFirst(s string) string

func UUID

func UUID() string

Types

type BitMap

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

func NewBitMap

func NewBitMap(max int) *BitMap

初始化一个BitMap 一个byte有8位,可代表8个数字,取余后加1为存放最大数所需的容量

func (*BitMap) Add

func (b *BitMap) Add(num int)

添加一个数字到位图 计算添加数字在数组中的索引index,一个索引可以存放8个数字 计算存放到索引下的第几个位置,一共0-7个位置 原索引下的内容与1左移到指定位置后做或运算

func (*BitMap) IsExist

func (b *BitMap) IsExist(num int) bool

判断一个数字是否在位图 找到数字所在的位置,然后做与运算

func (*BitMap) Max

func (b *BitMap) Max() int

位图的最大数字

func (*BitMap) Remove

func (b *BitMap) Remove(num int)

删除一个数字在位图 找到数字所在的位置取反,然后与索引下的数字做与运算

func (*BitMap) String

func (b *BitMap) String() string

Jump to

Keyboard shortcuts

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