utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 26 Imported by: 13

Documentation

Index

Constants

View Source
const (
	IntZero     = int(0)
	Int8Zero    = int8(0)
	Int16Zero   = int16(0)
	Int32Zero   = int32(0)
	Int64Zero   = int64(0)
	UintZero    = uint(0)
	Uint8Zero   = uint8(0)
	Uint16Zero  = uint16(0)
	Uint32Zero  = uint32(0)
	Uint64Zero  = uint64(0)
	Float32Zero = float32(0)
	Float64Zero = float64(0)
	StringZero  = ""
)

Variables

View Source
var Crypto *crypto

Functions

func Assert added in v1.1.0

func Assert(ps ...func() error) (err error)

func BytesToInt

func BytesToInt(b []byte, n interface{}) error

BytesToInt 字节转换成整形,n 必须是指针 var a int32 BytesToInt([]byte{1},&a)

func ConditionalOperator

func ConditionalOperator(op bool, a, b interface{}) interface{}

func Empty added in v0.0.2

func Empty(data interface{}) bool

func EmptyReflect added in v0.0.2

func EmptyReflect(object interface{}) bool

EmptyReflect 通过反射判断复杂类型是否为空,一般确定参数不为基础类型时才直接使用,否则应该使用 IsEmpty

func FloatPrecision added in v1.1.0

func FloatPrecision(value float64, precision float64) float64

FloatPrecision 四舍五入,保留到Precision位小数

func GZipCompress

func GZipCompress(data []byte) []byte

func GZipUnCompress

func GZipUnCompress(data []byte) ([]byte, error)

func GetIPv4ByInterface

func GetIPv4ByInterface(name string) ([]string, error)

GetIPv4ByInterface return IPv4 address from a specific interface IPv4 addresses

func IncludeNotPrintableChar added in v1.0.7

func IncludeNotPrintableChar(s string) bool

func Int32SliceIndexOf

func Int32SliceIndexOf(s []int32, tar int32) int

func IntToBuffer

func IntToBuffer(buffer *bytes.Buffer, n interface{}) error

IntToBuffer 将数字写入BUFFER, buffer := bytes.NewBuffer([]byte{})

func IntToBytes

func IntToBytes(n interface{}) ([]byte, error)

IntToBytes 整形转换成字节

func Ipv4Decode

func Ipv4Decode(code uint64) string

func Ipv4Encode

func Ipv4Encode(address string) uint64

Ipv4Encode Ip2Int Ipv4 转uint64

func IsOsBindError

func IsOsBindError(err error) bool

IsOsBindError 是否端口绑定错误

func LocalIPv4s

func LocalIPv4s() ([]string, error)

LocalIPs return all non-loopback IPv4 addresses

func MD5

func MD5(data string) string

func NewCrypto

func NewCrypto(encoding *base64.Encoding) *crypto

func NewUrl

func NewUrl(address, scheme string) (*url.URL, error)

func PKCS7Padding

func PKCS7Padding(data []byte, blockSize int) []byte

PKCS7Padding 填充字节的函数

func PKCS7UnPadding

func PKCS7UnPadding(data []byte) []byte

PKCS7UnPadding 去除填充字节的函数

func SHA256

func SHA256(message string) string

func SliceStringToInt32

func SliceStringToInt32(s []string) []int32

func Sprintf added in v0.0.2

func Sprintf(format interface{}, args ...interface{}) (r string)

func StringSliceIndexOf

func StringSliceIndexOf(s []string, tar string) int

func Timeout

func Timeout(d time.Duration, fn func() error) error

func Try

func Try(f func(), handle ...TryHandle)

func UTF8StringLen added in v1.1.0

func UTF8StringLen(str string) int

func ZlibCompress

func ZlibCompress(data []byte) []byte

func ZlibUnCompress

func ZlibUnCompress(data []byte) ([]byte, error)

Types

type Address

type Address struct {
	Port   int    `json:"port"`
	Host   string `json:"host"`
	Retry  int    `json:"retry"`
	Scheme string `json:"scheme"`
}

func NewAddress

func NewAddress(address ...string) (r *Address)

NewAddress 解析url,scheme:默认协议

func (*Address) Empty added in v1.1.0

func (this *Address) Empty() bool

func (*Address) Handle

func (this *Address) Handle(handle func(network, address string) error) (err error)

func (*Address) HandleWithNetwork

func (this *Address) HandleWithNetwork(handle func(address string) error) (err error)

HandleWithNetwork network 写入地址中,tcp://0.0.0.0:80

func (*Address) Parse

func (this *Address) Parse(address string)

func (*Address) String

func (this *Address) String(withScheme ...bool) string

String 转换成string

type CryptoType

type CryptoType int
const (
	CryptoTypeDES CryptoType = iota //秘钥长度8字节 也就是64位
	CryptoTypeAES                   //秘钥长度位16 24 32 字节 也就是128 192 256位。
	CryptoType3DES
)

type Job

type Job func(TaskData)

Job callback function

type TaskData

type TaskData map[interface{}]interface{}

TaskData callback params

type TimeWheel

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

time wheel struct

func New

func New(interval time.Duration, slotNum int) *TimeWheel

New create a empty time wheel

func (*TimeWheel) AddTask

func (tw *TimeWheel) AddTask(interval time.Duration, times int, key interface{}, data TaskData, job Job) error

AddTask add new task to the time wheel

func (*TimeWheel) RemoveTask

func (tw *TimeWheel) RemoveTask(key interface{}) error

RemoveTask remove the task from time wheel

func (*TimeWheel) Start

func (tw *TimeWheel) Start()

Start start the time wheel

func (*TimeWheel) Stop

func (tw *TimeWheel) Stop()

Stop stop the time wheel

func (*TimeWheel) UpdateTask

func (tw *TimeWheel) UpdateTask(key interface{}, interval time.Duration, taskData TaskData) error

UpdateTask update task times and data

type TryHandle added in v0.0.2

type TryHandle func(any)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳