utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: BSD-3-Clause Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const SO_REUSEPORT = 15

Variables

View Source
var BytePool16k = NewBytePool(16 * 1024)
View Source
var BytePool1k = NewBytePool(1024)
View Source
var BytePool32k = NewBytePool(32 * 1024)
View Source
var BytePool4k = NewBytePool(4 * 1024)
View Source
var RegexpDigitNumber = regexp.MustCompile(`^\d+$`)
View Source
var SharedBufferPool = NewBufferPool()
View Source
var SharedFreeHoursManager = NewFreeHoursManager()

Functions

func CleanPath

func CleanPath(path string) string

CleanPath 清理Path中的多余的字符

func CopyWithFilter

func CopyWithFilter(writer io.Writer, reader io.Reader, buf []byte, filter func(p []byte) []byte) (written int64, err error)

func DumpResponse

func DumpResponse(resp *http.Response) (header []byte, body []byte, err error)

DumpResponse 导出响应

func EqualStrings added in v0.5.8

func EqualStrings(s1 []string, s2 []string) bool

EqualStrings 检查两个字符串slice内容是否一致

func Exit

func Exit()

func FormatAddress

func FormatAddress(addr string) string

FormatAddress format address

func FormatAddressList

func FormatAddressList(addrList []string) []string

FormatAddressList format address list

func GMTTime

func GMTTime(t time.Time) time.Time

GMTTime 计算GMT时间

func GMTUnixTime

func GMTUnixTime(timestamp int64) int64

GMTUnixTime 计算GMT时间戳

func Get

func Get(object interface{}, keys []string) interface{}

func IP2Long

func IP2Long(ip string) uint64

IP2Long 将IP转换为整型 注意IPv6没有顺序

func IsIPv4

func IsIPv4(ip string) bool

IsIPv4 是否为IPv4

func IsIPv6

func IsIPv6(ip string) bool

IsIPv6 是否为IPv6

func IsLocalIP

func IsLocalIP(ipString string) bool

IsLocalIP 判断是否为本地IP

func ListenReuseAddr

func ListenReuseAddr(network string, addr string) (net.Listener, error)

ListenReuseAddr 监听可重用的端口

func LookupCNAME

func LookupCNAME(host string) (string, error)

LookupCNAME 获取CNAME

func MaxInt

func MaxInt(min1 int, min2 int) int

func MergePorts added in v0.4.10

func MergePorts(ports []int) [][2]int

MergePorts 聚合端口 返回 [ [fromPort, toPort], ... ]

func MinInt

func MinInt(min1 int, min2 int) int

func NewHTTPClient

func NewHTTPClient(timeout time.Duration) *http.Client

NewHTTPClient 获取一个新的Client

func ParseAddrHost added in v0.4.9

func ParseAddrHost(addr string) string

ParseAddrHost 分析地址中的主机名部分

func PrintError

func PrintError(err error)

func RemoveWorkspace

func RemoveWorkspace(path string) string

func SetRLimit

func SetRLimit(limit uint64) error

SetRLimit set resource limit

func SetSuitableRLimit

func SetSuitableRLimit() error

SetSuitableRLimit set best resource limit value

func SharedHttpClient

func SharedHttpClient(timeout time.Duration) *http.Client

SharedHttpClient 获取一个公用的Client

func SimpleDecrypt

func SimpleDecrypt(data []byte) []byte

SimpleDecrypt 解密特殊信息

func SimpleDecryptMap

func SimpleDecryptMap(base64String string) (maps.Map, error)

func SimpleEncrypt

func SimpleEncrypt(data []byte) []byte

SimpleEncrypt 加密特殊信息

func SimpleEncryptMap

func SimpleEncryptMap(m maps.Map) (base64String string, err error)

func SystemMemoryGB

func SystemMemoryGB() int

SystemMemoryGB 系统内存GB数量 必须保证不小于1

func ToValidUTF8string

func ToValidUTF8string(v string) string

ToValidUTF8string 去除字符串中的非UTF-8字符

func UnsafeBytesToString

func UnsafeBytesToString(bs []byte) string

UnsafeBytesToString convert bytes to string

func UnsafeStringToBytes

func UnsafeStringToBytes(s string) []byte

UnsafeStringToBytes convert string to bytes

func VersionToLong

func VersionToLong(version string) uint32

计算版本代号

Types

type AES256CFBMethod

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

func (*AES256CFBMethod) Decrypt

func (this *AES256CFBMethod) Decrypt(dst []byte) (src []byte, err error)

func (*AES256CFBMethod) Encrypt

func (this *AES256CFBMethod) Encrypt(src []byte) (dst []byte, err error)

func (*AES256CFBMethod) Init

func (this *AES256CFBMethod) Init(key, iv []byte) error

type BufferPool

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

BufferPool pool for get byte slice

func NewBufferPool

func NewBufferPool() *BufferPool

NewBufferPool 创建新对象

func (*BufferPool) Get

func (this *BufferPool) Get() (b *bytes.Buffer)

Get 获取一个新的Buffer

func (*BufferPool) Put

func (this *BufferPool) Put(b *bytes.Buffer)

Put 放回一个使用过的byte slice

type BytePool

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

BytePool pool for get byte slice

func NewBytePool

func NewBytePool(length int) *BytePool

NewBytePool 创建新对象

func (*BytePool) Get

func (this *BytePool) Get() []byte

Get 获取一个新的byte slice

func (*BytePool) Length

func (this *BytePool) Length() int

Length 单个字节slice长度

func (*BytePool) Put

func (this *BytePool) Put(b []byte)

Put 放回一个使用过的byte slice

type FreeHoursManager

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

FreeHoursManager 计算节点空闲时间 以便于我们在空闲时间执行高强度的任务,如清理缓存等

func NewFreeHoursManager

func NewFreeHoursManager() *FreeHoursManager

func (*FreeHoursManager) IsFreeHour

func (this *FreeHoursManager) IsFreeHour() bool

func (*FreeHoursManager) Start

func (this *FreeHoursManager) Start()

func (*FreeHoursManager) Stop

func (this *FreeHoursManager) Stop()

func (*FreeHoursManager) Update

func (this *FreeHoursManager) Update(bytes uint64)

type ServiceManager

type ServiceManager struct {
	Name        string
	Description string
	// contains filtered or unexported fields
}

服务管理器

func NewServiceManager

func NewServiceManager(name, description string) *ServiceManager

获取对象

func (*ServiceManager) Close

func (this *ServiceManager) Close() error

关闭

func (*ServiceManager) Install

func (this *ServiceManager) Install(exePath string, args []string) error

Install 安装服务

func (*ServiceManager) Log

func (this *ServiceManager) Log(msg string)

记录普通日志

func (*ServiceManager) LogError

func (this *ServiceManager) LogError(msg string)

记录错误日志

func (*ServiceManager) PauseWindow

func (this *ServiceManager) PauseWindow()

保持命令行窗口是打开的

func (*ServiceManager) Start

func (this *ServiceManager) Start() error

Start 启动服务

func (*ServiceManager) Uninstall

func (this *ServiceManager) Uninstall() error

Uninstall 删除服务

type Ticker

type Ticker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

Ticker 类似于time.Ticker,但能够真正地停止

func Every

func Every(duration time.Duration, f func(ticker *Ticker)) *Ticker

Every 定时运行某个函数

func NewTicker

func NewTicker(duration time.Duration) *Ticker

NewTicker 创建新Ticker

func (*Ticker) Next

func (this *Ticker) Next() bool

Next 查找下一个Tick

func (*Ticker) Stop

func (this *Ticker) Stop()

Stop 停止

type Unzip

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

func NewUnzip

func NewUnzip(zipFile string, targetDir string, stripPrefix string) *Unzip

func (*Unzip) Run

func (this *Unzip) Run() error

Jump to

Keyboard shortcuts

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