utils

package
v0.0.0-...-a8c716a Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogTimeFormatMill        = "2006-01-02 15:04:05.9999"
	LogTimeFormatSecond      = "2006-01-02 15:04:05"
	LogTimeFormat            = "2006-01-02 15:04"
	StrTimeFormat            = "20060102150405"
	StrTimeFormatMill        = "200601021504059999"
	YYYYMMDDHHmmSSTimeFormat = "2006年01月02日 15:04:05"
	YYYYMMDDTimeDotFormat    = "2006.01.02"
	MonthFormat              = "2006-01"
	ZreoS                    = "0s"
	YYYYMMDDFormat           = "2006-01-02"
	EarlyTime                = 1019101055000
	LateTime                 = 4111702655000
)
View Source
const (
	B  = 1
	KB = 1024 * B
	MB = 1024 * KB
	GB = 1024 * MB
)

Variables

View Source
var WithExpiryDuration = ants.WithExpiryDuration

WithExpiryDuration 设置清理协程的时间间隔

View Source
var WithLogger = ants.WithLogger

WithLogger 自定义logger

View Source
var WithPanicHandler = ants.WithPanicHandler

WithPanicHandler 自定义panic处理逻辑

Functions

func Base64Decode

func Base64Decode(b64Str string) (string, error)

base64解码

func Base64Encode

func Base64Encode(str string) string

base64编码

func Contanis

func Contanis(slice []string, value string) bool

判断一个string切片是否包含某个子字符串

func GenerateMD5

func GenerateMD5(s []byte) [16]byte

MD5

func GenerateMD5ToHex

func GenerateMD5ToHex(s []byte) string

func GenerateRandomKey

func GenerateRandomKey(length int) string

func GenerateRandomTaskID

func GenerateRandomTaskID(time time.Time) string

func GenerateRandomTaskName

func GenerateRandomTaskName(name string) string

func GetDayInterval

func GetDayInterval(millis int64) (startOfDay, endOfDay time.Time)

GetDayInterval 获取当前毫秒时间戳所在天的开始和结束shike

func GetProtocolMap

func GetProtocolMap() map[Protocol]string

func GetSplit

func GetSplit(input string) []string

func GetSplitD

func GetSplitD(input string) []string

func GetTimeMillis

func GetTimeMillis(tstr string) int64

根据时间获得毫秒级时间戳

func If

func If[T IfTrue](b bool, trueVal, falseVal T) T

func IsIPv4

func IsIPv4(ipStr string) (flag bool)

IsIPv4 判断地址为IPv4

func IsIPv6

func IsIPv6(ipStr string) (flag bool)

IsIPv6 判断地址为IPv6

func IsItemInSlice

func IsItemInSlice(s []any, k any) bool

func MakeJSONOutput

func MakeJSONOutput(data interface{}) string

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal 更加小的序列化

func MatchRootDomain

func MatchRootDomain(rawURL string) (string, error)

MatchRootDomain 匹配根域名

func MillisToTime

func MillisToTime(millis int64) time.Time

MillisToTime 毫秒数据戳转time

func ParseTime

func ParseTime(layout, timeStr string) (t time.Time)

解析时间, 如果解析错误, 返回"当前时间"

func ReadToBase64

func ReadToBase64(reader io.Reader) (string, error)

func ReadToBytes

func ReadToBytes(reader io.Reader) (data []byte, err error)

func SafeToString

func SafeToString(b []byte) string

func SetProtocol

func SetProtocol(host string, p Protocol) string

设置Protocol

func SliceSepByStep

func SliceSepByStep[T interface{}](originalSlice []T, step int) [][]T

func TrimProtocol

func TrimProtocol(host string) string

TrimProtocol消除Protocol

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

func UnsafeToString

func UnsafeToString(b []byte) string

UnsafeToString []byte to string 无需额外空间

func WithProtocol

func WithProtocol(domain string) bool

WithProtocol 含协议字符串

Types

type ConcurrentPool

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

func NewPool

func NewPool(num int, opts ...ants.Option) (*ConcurrentPool, error)

NewPool 实例化预分配协程池

func (*ConcurrentPool) Release

func (c *ConcurrentPool) Release()

Release 释放这个协程池

func (*ConcurrentPool) Submit

func (c *ConcurrentPool) Submit(f func()) error

Submit 注册一个任务

func (*ConcurrentPool) Wait

func (c *ConcurrentPool) Wait()

Wait 等待阻塞

func (*ConcurrentPool) WaitAndRunNum

func (c *ConcurrentPool) WaitAndRunNum() (int, int)

WaitNum 等待执行的任务数

type IfTrue

type IfTrue interface {
	~bool | []string | any
}

type NetProtocol

type NetProtocol int

NetProtocol

const (
	Invalid NetProtocol = iota // 0. 无法解析
	IPv4                       // 1. IPv4
	IPv6                       // 2.IPv6
)

func JudgeNetProtocol

func JudgeNetProtocol(ipStr string) NetProtocol

JudgeNetProtocol 裁决ip字符串类型

func (NetProtocol) String

func (np NetProtocol) String() string

type Protocol

type Protocol int

Protocol 网络通信协议

const (
	HTTP Protocol = iota + 1
	HTTPS
)

func (Protocol) String

func (p Protocol) String() string

type ResolveType

type ResolveType string

域名解析类型

const (
	DefaultType ResolveType = ""     // 默认空值
	Atype       ResolveType = "A"    // IPv4
	AAAAtype    ResolveType = "AAAA" // IPv6
	CNAMEtype   ResolveType = "CNAME"
	MXtype      ResolveType = "MX"
	NStype      ResolveType = "NS"
	PTRtype     ResolveType = "PTR"
	SOAtype     ResolveType = "SOA"
)

type StringSet

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

StringSet 定义一个string的set 用来做字符串的"交并补"操作

func NewStringSet

func NewStringSet(items ...string) *StringSet

NewStringSet 新建集合对象

func (*StringSet) Add

func (s *StringSet) Add(items ...string)

Add 添加元素

func (*StringSet) Clear

func (s *StringSet) Clear()

Clear 清空集合

func (*StringSet) Complement

func (s *StringSet) Complement(full *StringSet) *StringSet

Complement 两个stringSet补集

func (*StringSet) Count

func (s *StringSet) Count() int

Count 元素个数

func (*StringSet) Empty

func (s *StringSet) Empty() bool

Empty 空集合判断

func (*StringSet) Has

func (s *StringSet) Has(items ...string) bool

Has 判断元素是否存在

func (*StringSet) Intersect

func (s *StringSet) Intersect(sets ...*StringSet) *StringSet

Intersect 交集

func (*StringSet) List

func (s *StringSet) List() []string

List 无序列表

func (*StringSet) Minus

func (s *StringSet) Minus(sets ...*StringSet) *StringSet

Minus 差集

func (*StringSet) PopN

func (s *StringSet) PopN(n int) []string

PopN 弹出N个数据 n: <=0 时, 与List()相同; n > Count()时, 与List()相同;

func (*StringSet) Remove

func (s *StringSet) Remove(items ...string)

Remove 删除元素

func (*StringSet) SortList

func (s *StringSet) SortList() []string

SortList 排序列表

func (*StringSet) Union

func (s *StringSet) Union(sets ...*StringSet) *StringSet

Union 并集

Jump to

Keyboard shortcuts

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