utils

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 27 Imported by: 6

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
View Source
var Random *random
View Source
var Time = times.New()

Functions

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 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 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 NewRandom

func NewRandom(randomStringSeed string) *random

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 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) 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 Emitter

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

func NewEmitter

func NewEmitter(breakOnError bool) *Emitter

func (*Emitter) Emit

func (this *Emitter) Emit(ename string) (errs []error)

func (*Emitter) On

func (this *Emitter) On(ename string, callback EventsFunc)

type EventsFunc

type EventsFunc func() error

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)

type Worker

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

Worker 工作进程管理器,并发安全

func NewWorker

func NewWorker(num int32, handle func(interface{})) *Worker

func (*Worker) Close

func (this *Worker) Close()

关闭Worker

func (*Worker) Emit

func (this *Worker) Emit(msg interface{}) (ret bool)

func (*Worker) Fork

func (this *Worker) Fork()

创建WORKER协程

Jump to

Keyboard shortcuts

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