utils

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 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()

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 CutPrefix added in v1.3.0

func CutPrefix(s, prefix string) (after string, found bool)

CutPrefix returns s without the provided leading prefix string and reports whether it found the prefix. If s doesn't start with prefix, CutPrefix returns s, false. If prefix is the empty string, CutPrefix returns s, true.

copy from go source

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 IsWildIP added in v1.2.9

func IsWildIP(v string) bool

IsWildIP 宽泛地判断一个数据是否为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 SystemMemoryBytes added in v1.2.11

func SystemMemoryBytes() uint64

SystemMemoryBytes 系统内存总字节数

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 ServiceManager

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

ServiceManager 服务管理器

func NewServiceManager

func NewServiceManager(name, description string) *ServiceManager

获取对象

func (*ServiceManager) Close

func (this *ServiceManager) Close() error

Close 关闭

func (*ServiceManager) Install

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

Install 安装服务

func (*ServiceManager) Log

func (this *ServiceManager) Log(msg string)

Log 记录普通日志

func (*ServiceManager) LogError

func (this *ServiceManager) LogError(msg string)

LogError 记录错误日志

func (*ServiceManager) PauseWindow

func (this *ServiceManager) PauseWindow()

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