utils

package
v0.0.0-...-1a2806f Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

* @Author: your name * @Date: 2021-06-07 09:13:06 * @LastEditTime: 2021-08-12 17:13:29 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: /nethopper/utils/token.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(i int) int

Abs int取绝对值

func Abs32

func Abs32(i int32) int32

Abs32 int32取绝对值

func CallOpt

func CallOpt() int32

CallOpt 获取随机opt

func CopyFloat32Map

func CopyFloat32Map(source map[int32]float32) map[int32]float32

func CopyFloat64Map

func CopyFloat64Map(source map[int32]float64) map[int32]float64

func CopyInt32Map

func CopyInt32Map(source map[int32]int32) map[int32]int32

func CopyInt64Map

func CopyInt64Map(source map[int32]int64) map[int32]int64

func CopyJSON

func CopyJSON(marshaler interface{}, unMarshaler interface{}) error

func CopyMapInt32

func CopyMapInt32(a map[int32]int32) map[int32]int32

func CreateRandArray

func CreateRandArray(max int, length int) []int

CreateRandArray 创建随机数 [0,max)数组,返回随机数序列,可能会有重复

func CreateToken

func CreateToken(secret string, content string, expire time.Duration) (string, error)

CreateToken token create

func CreateUniqRandArray

func CreateUniqRandArray(max int, length int) []int

CreateUniqRandArray 创建唯一随机数 [0,max)数组,返回一个数组序列,没有重复数

func DeepClone

func DeepClone(v interface{}) interface{}

func DeepCoderCopy

func DeepCoderCopy(dst, src interface{}) error

func DeepCopy

func DeepCopy(dst, src interface{})

func Dump

func Dump(data ...interface{})

Dump print the data in console

func FileIsExist

func FileIsExist(path string) bool

FileIsExist if file exist ,return true

func FileLines

func FileLines(filename string) (int32, error)

FileLines get file lines

func FilterByGeneric

func FilterByGeneric[V any](elems []V, predicate func(V) bool) []V

func FilterOneByGeneric

func FilterOneByGeneric[V any](elems []V, predicate func(V) bool) V

func Float64Bits

func Float64Bits(f float64, d int)

打印浮点数的特定表现格式

func GenUID

func GenUID() uint64

GenUID

func GenUUID

func GenUUID() string

GenUUID create uuid based on random numbers

func GetAbsDirectory

func GetAbsDirectory(filename string) string

GetAbsDirectory get file directory abs path

func GetAbsFilePath

func GetAbsFilePath(filename string) string

GetAbsFilePath get file abs path

func GetDumpString

func GetDumpString(data ...interface{}) string

GetDumpString return data print string

func GetEmptyTime

func GetEmptyTime() time.Time

GetEmptyTime 获取空时间结构

func GetGID

func GetGID() uint64

func GetLocalIP

func GetLocalIP() string

GetLocalIP get local ip

func GetTodayHourTime

func GetTodayHourTime(hour int) time.Time

GetTodayHourTime 获取当天整点时间

func GetTodayTime

func GetTodayTime() time.Time

GetTodayTime 获取当天开始时间

func GetTomorrowTime

func GetTomorrowTime() time.Time

GetTomorrowTime 获取明天的开始时间

func GetWorkDirectory

func GetWorkDirectory() (string, error)

GetWorkDirectory get current exec file directory

func Hour

func Hour(t time.Time) int64

Hour 获取整点时间戳

func HourNow

func HourNow() string

HourNow 现在小时字符串

func HourTimestamp

func HourTimestamp() int64

HourTimestamp 获取整点时间戳

func I32Clamp

func I32Clamp(value, min, max int32) int32

I32Clamp 取中间值

func I32Max

func I32Max(a, b int32) int32

I32Max 取2数最大

func I32Min

func I32Min(a, b int32) int32

I32Min 取2数最小

func I64Clamp

func I64Clamp(value, min, max int64) int64

I64Clamp 取中间值

func I64Max

func I64Max(a, b int64) int64

I64Max 取2数最大

func I64Min

func I64Min(a, b int64) int64

I64Min 取2数最小

func IClamp

func IClamp(value, min, max int) int

IClamp 取中间值

func IMax

func IMax(a, b int) int

IMax 取2数最大

func IMin

func IMin(a, b int) int

IMin 取2数最小

func Implode

func Implode(list interface{}, seq string) string

Implode arr to string

func InitUID

func InitUID(workID uint16)

InitUID uidGenerater workerID between 1-255

func Int64ToString

func Int64ToString(v int64) string

Int64ToString convert int64 to string

func InvSqrt

func InvSqrt(x float32) float32

InvSqrt 平方根倒数速算法

func JSON2Map

func JSON2Map(s string) (map[string]interface{}, error)

JSON2Map json 转换为 map

func LocalMilliscond

func LocalMilliscond() int64

LocalMilliscond 当前毫秒

func LocalTimestamp

func LocalTimestamp() int64

LocalTimestamp 当前时间戳秒

func Map2Struct

func Map2Struct(data map[string]interface{}, out interface{}) error

Map2Struct map转换为struct

func MargeMap

func MargeMap(a map[int32]int32, b map[int32]int32)

func PowerCalc

func PowerCalc(size int32) (int32, uint8)

PowerCalc return size & power

func PrintPointerInfo

func PrintPointerInfo(buf *bytes.Buffer, headlen int, pointers *pointerInfo)

PrintPointerInfo dump pointer value

func RandomInt

func RandomInt(from, to int) int

RandomInt 随机范围取值[from, to]

func RandomInt32

func RandomInt32(from, to int32) int32

RandomInt32 随机范围取值[from, to]

func RandomMultiWeight

func RandomMultiWeight(weightMapping map[int32]int32, count int) []int32

RandomMultiWeight 随机多个权重

func RandomWeight

func RandomWeight(weightMapping map[int32]int32) int32

RandomWeight 随机权重

func Round

func Round(value float64) int32

Round int32取整 四舍五入

func Round64

func Round64(value float64) int64

Round64 int64取整 四舍五入

func RoundFloat64

func RoundFloat64(value float64) float64

RoundFloat64 float64取整 四舍五入

func RoundN

func RoundN(f float64, n int) float64

RoundN 小数点保留N位

func RuntimeStats

func RuntimeStats(gc bool, heapObj bool, goroutineNum bool) []int64

获取常用runtime统计信息

func Shuffle

func Shuffle(list []interface{})

Shuffle 随机乱序,洗牌

func ShuffleI

func ShuffleI(list []int)

ShuffleI 随机乱序

func ShuffleI32

func ShuffleI32(list []int32)

ShuffleI32 随机乱序

func ShuffleN

func ShuffleN(list []interface{}, randCount int) []interface{}

ShuffleN 随机抽取n张

func ShuffleNI32

func ShuffleNI32(list []int32, randCount int) []int32

ShuffleNI32 随机抽取n张

func ShuffleR

func ShuffleR(list []interface{})

ShuffleR 随机乱序,洗牌,反向,效果一样

func Stack

func Stack(skip int, indent string) []byte

Stack get stack bytes

func StaticRand

func StaticRand(seedrare, min, max int) int

StaticRand 固定种子伪随机

func Str2Bool

func Str2Bool(s string) bool

Str2Bool string convert to bool

func Str2Float32

func Str2Float32(s string) float32

Str2Float32 string convert to Float32

func Str2Float64

func Str2Float64(s string) float64

Str2Float64 string convert to Float64

func Str2Int

func Str2Int(s string) int

Str2Int string convert to Int

func Str2Int16

func Str2Int16(s string) int16

Str2Int16 string convert to Int16

func Str2Int32

func Str2Int32(s string) int32

Str2Int32 string convert to Int32

func Str2Int64

func Str2Int64(s string) int64

Str2Int64 string convert to Int64

func Str2Int8

func Str2Int8(s string) int8

Str2Int8 string convert to Int8

func Str2Uint

func Str2Uint(s string) uint

Str2Uint string convert to Uint

func Str2Uint16

func Str2Uint16(s string) uint16

Str2Uint16 string convert to Uint16

func Str2Uint32

func Str2Uint32(s string) uint32

Str2Uint32 string convert to Uint32

func Str2Uint64

func Str2Uint64(s string) uint64

Str2Uint64 string convert to Uint64

func Str2Uint8

func Str2Uint8(s string) uint8

Str2Uint8 string convert to Uint8

func StrSub

func StrSub(str string, start int, end int) string

StrSub 字符串截取

func StringToInt64

func StringToInt64(s string) int64

StringToInt64 convert string to int64,if err return 0

func Struct2Map

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

Struct2Map struct 2 map

func SumI32

func SumI32(list []int32) int32

SumI32 数组求和

func SumMatrixColI32

func SumMatrixColI32(mat [][]int32, col int) int32

SumMatrixColI32 矩阵列求和

func TimeFormat

func TimeFormat(t time.Time) string

TimeFormat 时间戳格式化

func TimeYMD

func TimeYMD() string

TimeYMD get current time return format yearmouthday

func TimeYMDH

func TimeYMDH() string

TimeYMDH get current time return format yearmouthday-hour

func TimeYMDHIS

func TimeYMDHIS() string

TimeYMDHIS get current time return format yearmouthday hour:minute:second

func Today

func Today() string

Today 获取当前年月日

func TodayTimestamp

func TodayTimestamp() int64

TodayTimestamp 获取今天最早的时间戳毫秒

func Tomorrow

func Tomorrow() string

Tomorrow 获取明天年月日

func ValidToken

func ValidToken(secret string, token string) (string, error)

ValidToken token valid

Types

type Any

type Any = interface{}

Any is a substitute for interface{}

type BitFlag

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

BitFlag bit 位操作类

func (*BitFlag) Has

func (b *BitFlag) Has(pos uint8) bool

func (*BitFlag) Reset

func (b *BitFlag) Reset()

func (*BitFlag) Set

func (b *BitFlag) Set(pos uint8) uint64

func (*BitFlag) UnSet

func (b *BitFlag) UnSet(pos uint8) uint64

type Promise

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

func All

func All(promises ...*Promise) *Promise

All waits for all Promises to be resolved, or for any to be rejected.

func New

func New(executor func(resolve func(Any), reject func(error))) *Promise

New instantiates and returns a pointer to a new Promise.

func Reject

func Reject(err error) *Promise

Reject returns a Promise that has been rejected with a given error.

func Resolve

func Resolve(resolution Any) *Promise

Resolve returns a Promise that has been resolved with a given value.

func (*Promise) Await

func (promise *Promise) Await() (Any, error)

Await is a blocking function that waits for all callbacks to be executed.

func (*Promise) Catch

func (promise *Promise) Catch(rejection func(err error) error) *Promise

Catch Appends a rejection handler to the promise, and returns a new promise resolving to the return value of the handler.

func (*Promise) Then

func (promise *Promise) Then(fulfillment func(data Any) Any) *Promise

Then appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.

type Time

type Time struct {
	time.Time
}

Time 可在JSON中序列化的时间类型

func Now

func Now() Time

Now 当前时间的JSONTime格式

func StrToJSONTime

func StrToJSONTime(source string, layout string) (Time, error)

StrToJSONTime 字符串转换为JSONTime layout为""时默认使用2006-01-02 15:04:05格式 其他时候使用layout的format

func StrToTime

func StrToTime(source string) Time

StrToTime string format to time struct

func ToTime

func ToTime(m time.Time) Time

ToTime to json time 由Time生成NullTime

func (Time) Date

func (m Time) Date() string

Date get date string

func (Time) MarshalJSON

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

MarshalJSON on JSONTime format Time field with %Y-%m-%d %H:%M:%S

func (Time) RedisArg

func (m Time) RedisArg() interface{}

RedisArg 支持redis日期的序列化

func (*Time) RedisScan

func (m *Time) RedisScan(src interface{}) error

RedisScan 支持redis反序列化

func (*Time) Scan

func (m *Time) Scan(v interface{}) error

Scan valueof time.Time

func (Time) String

func (m Time) String() string

String 返回JSONTime的字符串格式 YYYY-MM-DD HH:MM:SS

func (Time) Timestamp

func (m Time) Timestamp() string

Timestamp 返回时间戳格式的字符串

func (*Time) UnmarshalJSON

func (m *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON JSON反序列接口的实现

func (Time) Value

func (m Time) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

Directories

Path Synopsis
crypto
aes
md5

Jump to

Keyboard shortcuts

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