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: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPortsToFirewall

func AddPortsToFirewall(ports []int)

func CeilUnixTime added in v0.5.6

func CeilUnixTime(seconds int) int64

CeilUnixTime 取整并加1

func ContainsStringInsensitive

func ContainsStringInsensitive(list []string, search string) bool

ContainsStringInsensitive 检查是否包含某个字符串,并且不区分大小写

func DumpResponse

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

DumpResponse 导出响应

func EqualConfig added in v0.5.3

func EqualConfig(config1 any, config2 any) bool

EqualConfig 使用JSON对比配置

func FixMonthMaxDay added in v0.5.6

func FixMonthMaxDay(day string) (string, error)

FixMonthMaxDay 修正日期最大值

func FloorUnixTime added in v0.5.6

func FloorUnixTime(seconds int) int64

FloorUnixTime 取整

func GMTTime added in v0.5.6

func GMTTime(t time.Time) time.Time

GMTTime 计算GMT时间

func GMTUnixTime added in v0.5.6

func GMTUnixTime(timestamp int64) int64

GMTUnixTime 计算GMT时间戳

func GroupMinuteRanges added in v0.4.9

func GroupMinuteRanges(minutes []timeDayMinute) []timeDayMinuteRange

GroupMinuteRanges 将时间点分组

func IP2Long

func IP2Long(ip string) uint64

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

func IsIPv6

func IsIPv6(ip string) bool

IsIPv6 判断是否为IPv6

func JSONClone added in v1.0.0

func JSONClone[T any](ptr T) (newPtr T, err error)

JSONClone 使用JSON协议克隆对象

func LastDayInMonth added in v0.5.6

func LastDayInMonth(month string) (string, error)

LastDayInMonth 某月的最后一天 month: YYYYMM 返回 YYYYMMDD

func LimitString added in v0.5.2

func LimitString(s string, maxLength int) string

LimitString 限制字符串长度

func LookupCNAME added in v0.5.3

func LookupCNAME(host string) (string, error)

LookupCNAME 查询CNAME记录 TODO 可以设置使用的DNS主机地址

func LookupNS added in v0.5.3

func LookupNS(host string) ([]string, error)

LookupNS 查询NS记录 TODO 可以设置使用的DNS主机地址

func LookupTXT added in v0.5.3

func LookupTXT(host string) ([]string, error)

LookupTXT 获取CNAME TODO 可以设置使用的DNS主机地址

func NewHTTPClient

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

NewHTTPClient 获取一个新的Client

func NextMinuteUnixTime added in v0.5.6

func NextMinuteUnixTime() int64

NextMinuteUnixTime 获取下一分钟开始的时间戳

func ParseDomainFromKey

func ParseDomainFromKey(key string) (domain string)

ParseDomainFromKey 从Key中获取域名

func PrintError

func PrintError(err error)

打印错误

func Range24HourTimes added in v0.5.6

func Range24HourTimes(everyMinutes int32) ([]string, error)

Range24HourTimes 计算24小时时间点 从 00:00 - 23:59

func RangeDays

func RangeDays(dayFrom string, dayTo string) ([]string, error)

RangeDays 计算日期之间的所有日期,格式为YYYYMMDD

func RangeHours

func RangeHours(hourFrom string, hourTo string) ([]string, error)

RangeHours 计算小时之间的所有小时,格式为YYYYMMDDHH

func RangeMinutes added in v0.4.9

func RangeMinutes(toTime time.Time, count int, everyMinutes int32) []timeDayMinute

RangeMinutes 计算若干个时间点,返回结果为 [ [day1, minute1], [day2, minute2] ... ]

func RangeMonths

func RangeMonths(dayFrom string, dayTo string) ([]string, error)

RangeMonths 计算日期之间的所有月份,格式为YYYYMM

func RangeTimes added in v0.5.6

func RangeTimes(timeFrom string, timeTo string, everyMinutes int32) (result []string, err error)

RangeTimes 计算时间点

func SetRLimit

func SetRLimit(limit uint64) error

set resource limit

func SetSuitableRLimit

func SetSuitableRLimit()

set best resource limit value

func Sha1RandomString added in v0.4.9

func Sha1RandomString() string

func SharedHttpClient

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

SharedHttpClient 获取一个公用的Client

func Similar added in v0.5.0

func Similar(s1 string, s2 string) float32

Similar 计算相似度 between 0-1

func SplitKeywordArgs added in v1.0.0

func SplitKeywordArgs(s string) (args []splitArg)

SplitKeywordArgs 分隔关键词参数 支持:hello, "hello", name:hello, name:"hello", name:\"hello\"

func SplitStrings

func SplitStrings(s string, glue string) []string

SplitStrings 分隔字符串 忽略其中为空的片段

func SystemMemoryGB added in v0.4.9

func SystemMemoryGB() int

func UnixTime added in v0.5.6

func UnixTime() int64

UnixTime 最快获取时间戳的方式,通常用在不需要特别精确时间戳的场景

func UnixTimeMilli added in v0.5.6

func UnixTimeMilli() int64

UnixTimeMilli 获取时间戳,精确到毫秒

func UnixTimeMilliString added in v0.5.6

func UnixTimeMilliString() (int64, string)

func ValidateEmail added in v0.5.3

func ValidateEmail(email string) bool

ValidateEmail 校验电子邮箱格式

func VersionToLong

func VersionToLong(version string) uint32

计算版本代号

Types

type CacheMap

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

func NewCacheMap

func NewCacheMap() *CacheMap

func (*CacheMap) Get

func (this *CacheMap) Get(key string) (value interface{}, ok bool)

func (*CacheMap) Len

func (this *CacheMap) Len() int

func (*CacheMap) Put

func (this *CacheMap) Put(key string, value interface{})

type Progress added in v0.5.3

type Progress struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

Progress 进度表示

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

安装服务

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

启动服务

func (*ServiceManager) Uninstall

func (this *ServiceManager) Uninstall() error

删除服务

type Ticker

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

func NewTicker

func NewTicker(duration time.Duration) *Ticker

func (*Ticker) Stop

func (this *Ticker) Stop()

func (*Ticker) Wait

func (this *Ticker) Wait() bool

type Unzip

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

func NewUnzip

func NewUnzip(zipFile string, targetDir string) *Unzip

func (*Unzip) Run

func (this *Unzip) Run() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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