utils

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B  = 1
	KB = 1024 * B
	MB = 1024 * KB
	GB = 1024 * MB
)

Variables

This section is empty.

Functions

func ArrayToString

func ArrayToString(array []interface{}) string

func AutoClearCode

func AutoClearCode(filepath string, codeData string) error

func AutoInjectionCode

func AutoInjectionCode(filepath string, funcName string, codeData string) error

func BcryptCheck

func BcryptCheck(password, hash string) bool

BcryptCheck 对比明文密码和数据库的哈希值

func BcryptHash

func BcryptHash(password string) string

BcryptHash 使用 bcrypt 对密码进行加密

func BreakPointContinue

func BreakPointContinue(content []byte, fileName string, contentNumber int, contentTotal int, fileMd5 string) (string, error)

func CheckMd5

func CheckMd5(content []byte, chunkMd5 string) (CanUpload bool)

func DateFormat

func DateFormat(t time.Time) string

func FirstLower

func FirstLower(s string) string

func FirstUpper

func FirstUpper(s string) string

func InterfaceToStruct

func InterfaceToStruct(data interface{}, v any) error

func JSONLoadFromFile

func JSONLoadFromFile(filePath string, data interface{}) error

func JsonField

func JsonField(msg string, v any) zap.Field

func MD5V

func MD5V(str []byte, b ...byte) string

func MaheHump

func MaheHump(s string) string

MaheHump 将字符串转换为驼峰命名

func MakeAddr

func MakeAddr(host string, port int) string

func MakeFile

func MakeFile(fileName string, FileMd5 string) (string, error)

func MapToStruct

func MapToStruct(data map[string]interface{}, v any) error

func MilliStamp

func MilliStamp() int64

func MillisToTime

func MillisToTime(millis int64) time.Time

func NowString

func NowString() string

func ParseDuration

func ParseDuration(d string) (time.Duration, error)

func Pointer

func Pointer[T any](in T) (out *T)

func Reload

func Reload() error

func RemoveChunk

func RemoveChunk(FileMd5 string) error

func Sort

func Sort(length int, less func(i, j int) bool, swap func(i, j int))

func Stamp

func Stamp() int64

func StructToMap

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

func TimeField

func TimeField(msg string, t time.Time) zap.Field

func ToJSON

func ToJSON(v any) string

func Unzip

func Unzip(zipFile string, destDir string) ([]string, error)

解压

func UpdateStampOffset

func UpdateStampOffset(stamp int64)

func ZipFiles

func ZipFiles(filename string, files []string, oldForm, newForm string) error

Types

type Cache

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

Cache 是一个内存缓存的简单实现

func NewCache

func NewCache() *Cache

NewCache 创建一个新的缓存实例

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

Get 获取与一个键关联的值

func (*Cache) Set

func (c *Cache) Set(key string, value interface{})

Set 将一个值与一个键关联

type CountRef

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

func MakeCountRef

func MakeCountRef() *CountRef

func (*CountRef) Count

func (c *CountRef) Count() int

func (*CountRef) Release

func (c *CountRef) Release() int

func (*CountRef) Retain

func (c *CountRef) Retain() int

type Cpu

type Cpu struct {
	Cpus  []float64 `json:"cpus"`
	Cores int       `json:"cores"`
}

func InitCPU

func InitCPU() (c Cpu, err error)

type Disk

type Disk struct {
	UsedMB      int `json:"usedMb"`
	UsedGB      int `json:"usedGb"`
	TotalMB     int `json:"totalMb"`
	TotalGB     int `json:"totalGb"`
	UsedPercent int `json:"usedPercent"`
}

func InitDisk

func InitDisk() (d Disk, err error)

type Element

type Element interface{}

type Os

type Os struct {
	GOOS         string `json:"goos"`
	NumCPU       int    `json:"numCpu"`
	Compiler     string `json:"compiler"`
	GoVersion    string `json:"goVersion"`
	NumGoroutine int    `json:"numGoroutine"`
}

func InitOS

func InitOS() (o Os)

type Ram

type Ram struct {
	UsedMB      int `json:"usedMb"`
	TotalMB     int `json:"totalMb"`
	UsedPercent int `json:"usedPercent"`
}

func InitRAM

func InitRAM() (r Ram, err error)

type Server

type Server struct {
	Os   Os   `json:"os"`
	Cpu  Cpu  `json:"cpu"`
	Ram  Ram  `json:"ram"`
	Disk Disk `json:"disk"`
}

type Sorter

type Sorter struct {
	Length   int
	LessFunc func(i, j int) bool
	SwapFunc func(i, j int)
}

func (Sorter) Len

func (c Sorter) Len() int

func (Sorter) Less

func (c Sorter) Less(i, j int) bool

func (Sorter) Swap

func (c Sorter) Swap(i, j int)

type Stack

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

func NewStack

func NewStack(cap int) *Stack

初始化栈

func (*Stack) Cap

func (stack *Stack) Cap() int

Cap

func (*Stack) Clear

func (stack *Stack) Clear()

Clear

func (*Stack) Empty

func (stack *Stack) Empty() bool

func (*Stack) Len

func (stack *Stack) Len() int

Len

func (*Stack) Peek

func (stack *Stack) Peek() (ele Element, err error)

Peek

func (*Stack) Pop

func (stack *Stack) Pop() (ele Element, err error)

Pop

func (*Stack) Push

func (stack *Stack) Push(element Element) (err error)

Push

func (*Stack) Top

func (stack *Stack) Top() Element

type Time

type Time time.Time

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

type Timer

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

func StartTimer

func StartTimer(d time.Duration, cb func(*Timer) bool) *Timer

func (*Timer) Chan

func (c *Timer) Chan() <-chan time.Time

func (*Timer) Reset

func (c *Timer) Reset()

func (*Timer) Stop

func (c *Timer) Stop()

Directories

Path Synopsis
Package crc16 implements the 16-bit cyclic redundancy check, or CRC-16, checksum.
Package crc16 implements the 16-bit cyclic redundancy check, or CRC-16, checksum.

Jump to

Keyboard shortcuts

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