util

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 20 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigIntToIP added in v0.1.7

func BigIntToIP(i *big.Int) net.IP

func CalculateCIDR added in v0.1.7

func CalculateCIDR(startIP, endIP string) (string, error)

CIDR 计算

func CopyToClipboardUseOsc52 added in v0.1.7

func CopyToClipboardUseOsc52(str string) error

func DeepCopy

func DeepCopy(value any) any

func DeleteSelf

func DeleteSelf()

func Duration2String added in v0.1.7

func Duration2String(t time.Duration, secondPrecision ...string) string

func FindMissingNumbers added in v0.1.7

func FindMissingNumbers(numbers []int) []int

FindMissingNumbers 寻找连续数字中的空缺数字

func GetGitBranchHash

func GetGitBranchHash(url, branch string) (string, error)

func Getenv added in v0.1.6

func Getenv(key string, defaultValue string) string

func GroupNumbers added in v0.1.7

func GroupNumbers(numbers []int, groupSize int) [][]int

GroupNumbers 将连续数字进行分组 numbers 输入数字 groupSize 每组最多容纳数字个数,当groupSize <= 0时不做限制

func IpToBigInt added in v0.1.7

func IpToBigInt(ip net.IP) *big.Int

func IsProcessExist

func IsProcessExist(pid string) bool

func RandomPort

func RandomPort(start, end int, seed int64) int

返回随机端口

func Sha256 added in v0.1.4

func Sha256(data []byte) []byte

func TimeToPrt

func TimeToPrt(t time.Time) *time.Time

func Try added in v0.1.6

func Try(fn func()) (t *try)

func UniqueArray added in v0.1.7

func UniqueArray[T any, N any](data []N, f func(N) T) []T

UniqueArray 输出唯一数组

Types

type FileInfo

type FileInfo struct {
	Name        string `json:"name"`
	Path        string `json:"path"`
	Sha         string `json:"sha"`
	Size        int    `json:"size"`
	Url         string `json:"url"`
	HtmlUrl     string `json:"html_url"`
	GitUrl      string `json:"git_url"`
	DownloadUrl string `json:"download_url"`
	Type        string `json:"type"`
	Content     string `json:"content"`
	Encoding    string `json:"encoding"`
	Links       struct {
		Self string `json:"self"`
		Git  string `json:"git"`
		Html string `json:"html"`
	} `json:"_links"`
}

func GetGitHubFileInfo

func GetGitHubFileInfo(owner, repo, filePath string) (*FileInfo, error)

type MapItem added in v0.1.7

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

type Maps added in v0.1.7

type Maps map[uint8]*MapItem

func NewMap added in v0.1.7

func NewMap() Maps

func (Maps) Delete added in v0.1.7

func (m Maps) Delete(key string, f ...func())

func (Maps) Get added in v0.1.7

func (m Maps) Get(key string, f ...func(any, bool)) (any, bool)

func (Maps) Set added in v0.1.7

func (m Maps) Set(key string, value any, f ...func())

type Num added in v0.1.7

type Num interface {
	~int | ~uint | ~uint8 | ~int8 | ~int32 | ~uint32 | ~int64 | ~uint64 |
		~float32 | ~float64
}

type Snowflake added in v0.1.7

type Snowflake struct {
	// 基准时间
	BaseTime time.Time
	// 逻辑id,可以是部署的机器id
	LogicalId int64

	// 所有bit总和不能超过64
	// 毫秒时间所占长度,默认41bit 大概可以在基准时间上用69年左右
	BaseTimeBit int64
	// 默认13bit
	LogicalIdBit int64
	// 自增序列,默认10bit
	AutoIncrementBit int64
	// contains filtered or unexported fields
}

func (*Snowflake) GenerateId added in v0.1.7

func (s *Snowflake) GenerateId() (int64, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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