com

package module
v0.1.81 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2025 License: BSD-3-Clause Imports: 31 Imported by: 0

README

toolbox

介绍

go 工具箱

Documentation

Overview

用于处理字节的帮助程序

*

  • @Author : xingnan
  • @Email : 457415936@qq.com
  • @Time : 16:40
  • @File : conversion.go
  • @Project : toolbox
  • @Description : 计量单位

*

  • @Author : xingnan
  • @Email : 457415936@qq.com
  • @Time : 16:45
  • @File : daemonize.go
  • @Project : toolbox
  • @Description : 守护进程

*

  • @Author : xingnan
  • @Email : 457415936@qq.com
  • @Time : 16:46
  • @File : daemonize_posix.go
  • @Project : toolbox
  • @Description : GoLand

*

  • @Author : xingnan
  • @Email : 457415936@qq.com
  • @Time : 16:52
  • @File : env.go
  • @Project : toolbox
  • @Description : 环境变量

*

  • @Author : xingnan
  • @Email : 457415936@qq.com
  • @Time : 16:58
  • @File : fs.go
  • @Project : toolbox
  • @Description : 文件操作

*

  • @Author: xing nan
  • @Email:457415936@qq.com
  • @Time: 2020/12/28 上午8:02
  • @File : print
  • @Software: GoLand

Index

Constants

View Source
const (
	Kilo int64 = 1024
	KB   int64 = Kilo
	MB   int64 = KB * Kilo
	GB   int64 = MB * Kilo
	TB   int64 = GB * Kilo
	PB   int64 = TB * Kilo
	EB   int64 = PB * Kilo

	// MAX
	UINT64MAX uint64 = ^uint64(0)
	INT64MAX  int64  = int64(^uint64(0) >> 1)
	INT64MIN  int64  = -int64(^uint64(0) >> 1)
	UINT32MAX uint32 = ^uint32(0)
	INT32MAX  int32  = int32(^uint32(0) >> 1)
	INT32MIN  int32  = -int32(^uint32(0) >> 1)
	UINT16MAX uint16 = ^uint16(0)
	INT16MAX  int16  = int16(^uint16(0) >> 1)
	INT16MIN  int16  = -int16(^uint16(0) >> 1)
	UINT8MAX  uint8  = ^uint8(0)
	INT8MAX   int8   = int8(^uint8(0) >> 1)
	INT8MIN   int8   = -int8(^uint8(0) >> 1)
)

Conversion

Variables

This section is empty.

Functions

func AppDaemonizedEx

func AppDaemonizedEx(name, pidfile, stderr string) error

AppDaemonizedEx todo

func AppDir

func AppDir() string

func AppExit

func AppExit(name string, pidfile string, force bool) error

应用退出

func AppImmobilized

func AppImmobilized(pidfile string) error

AppImmobilized pid

func AppIsRunningEx

func AppIsRunningEx(pidfile string) (int, error)

AppIsRunningEx daemon is running

func AppRestart

func AppRestart(name string, pidfile string, arg ...string) error

应用重启

func ByteCat

func ByteCat(sv ...string) []byte

ByteCat return bytes.

func CountFileLine

func CountFileLine(name string) (int64, error)

@name 计算文件行数 @param filepath string 文件路径 @return int64 行数 @return error 错误类型

func CreateGUID

func CreateGUID() string

创建GUID

func Cut

func Cut(a []byte, from, to int) []byte

Cut 给定范围内的切片元素

func DelFile

func DelFile(file string) bool

删除文件

func EscapeNonBmpRune

func EscapeNonBmpRune(s string) string

EscapeNonBmpRune escape non BMP rune

func FileExist

func FileExist(filename string) bool

检查文件或目录是否存在 如果由 filename 指定的文件或目录存在则返回 true,否则返回 false

func FileType

func FileType(file string) string

文件类型

func Float64ToStr

func Float64ToStr(str float64) string

float64转为str并保留2位小数

func GetInternetIp

func GetInternetIp() string

获取本地外网IP

func GetLocalIPv4s

func GetLocalIPv4s() ([]string, error)

获取本地IPV4地址

func GetLocalIPv4sMacs

func GetLocalIPv4sMacs() ([]string, error)

获取IPV4及网卡地址

func GetLocalMacs

func GetLocalMacs() ([]string, error)

获取本地网卡地址

func GetLocalNetCount

func GetLocalNetCount() int

获取网卡数量

func GetUserHome

func GetUserHome() (string, error)

获取用户主目录

func HasNonBmpRune

func HasNonBmpRune(s string) bool

HasNonBmpRune todo BMP -> U+0000 to U+FFFF https://www.sttmedia.com/unicode-basiclingualplane

func Hmac

func Hmac(key, data string) string

func HmacSha256

func HmacSha256(secret string, data string) string

func Insert

func Insert(a []byte, i int, b []byte) []byte

Insert 在指定位置新建切片

func Ip2long

func Ip2long(ipstr string) uint32

@name ip v4 转为int

func Ipv4hexa2dec

func Ipv4hexa2dec(addr string) (string, error)

@name ipv4 16进制转10进制

func Ipv6hexa2str

func Ipv6hexa2str(addr string) (string, error)

@name ipv6 16进制转字符串

func IsNil

func IsNil(i interface{}) bool

判断动态值是否为空

func JsonDecode

func JsonDecode(data string) (interface{}, error)

json解码

func JsonEncode

func JsonEncode(data interface{}) (string, error)

json编码

func LocalIp

func LocalIp() string

本地IP

func LocalMac

func LocalMac() string

本地mac

func Long2ip

func Long2ip(ipLong uint32) string

@name int 转为 ip v4

func MakeGUID

func MakeGUID() string

func MakeRandomInt

func MakeRandomInt(num int) string

@name 生成随机数 num 数量

func MakeRandomStr

func MakeRandomStr() string

生成随机KEY

func Maximum64

func Maximum64(x, y int64) int64

Maximum64 todo

func Md5

func Md5(value string) string

func Minimum64

func Minimum64(x, y int64) int64

Minimum64 todo

func Mkdir

func Mkdir(path string) error

创建文件夹

func MkdirAll

func MkdirAll(path string) error

创建多级目录

func NewAppRestart

func NewAppRestart(name, pidfile string) error

new app restart only send SIGUSR2

func PathDirExists

func PathDirExists(p string) bool

文件目录是否存在

func PathExist

func PathExist(filename string) bool

检查文件或目录是否存在 如果由 filename 指定的文件或目录存在则返回 true,否则返回 false

func PathExists

func PathExists(p string) bool

路径是否存在

func PathSplit

func PathSplit(p string, suggestcap int) []string

PathSplit split path and

func Port4hexa2dec

func Port4hexa2dec(port string) (string, error)

* @name ip 16进制端口转10进制

func Print

func Print(args ...interface{})

Print 打印

func Printf

func Printf(format string, args ...interface{})

Printf 打印并格式化

func Println

func Println(args ...interface{})

Println 打印并换行

func RandString

func RandString(n int) string

创建随机串

func ReadFile

func ReadFile(path string) string

读取文本文件

func ReadFileByte

func ReadFileByte(path string) ([]byte, error)

读取文件

func ReadFileFirstLine

func ReadFileFirstLine(path string) (string, error)

读取文件第一行

func ReadLineCounter

func ReadLineCounter(path string) (int64, error)

读取文本行数

func ReadLines

func ReadLines(path string) ([]string, int, error)

逐行读取

func ReadLinesOffsetN

func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error)

逐行读取 offset 开始偏移量 读取行数,从偏移量offset开始

n >= 0: 最多 n 行
n < 0: 整个文件

func ReadStringForLine

func ReadStringForLine(path string, lineNumber int) string

读取定行文件

func Rename

func Rename(file string, to string) bool

文件重命名

func Replace

func Replace(a []byte, from, to int, new []byte) []byte

Replace 函数与字节不同。替换指定范围

func ReverseByte

func ReverseByte(s []byte) []byte

反向反转字节数组

func SecSha1

func SecSha1(pwd string) string

重复加密密码

func Sha1

func Sha1(s string) string

sha1加密

func SliceToString

func SliceToString(buf []byte) string

SliceToString 适用于大型有效载荷(零分配和更快)

func Sprint

func Sprint(args ...interface{}) string

Sprint 打印并返回

func Sprintf

func Sprintf(format string, args ...interface{}) string

Sprintf 格式化并返回

func Sprintln

func Sprintln(args ...interface{}) string

Sprintln 打印换行并返回

func StrCat

func StrCat(sv ...string) string

StrCat cat strings: You should know that StrCat gradually builds advantages only when the number of parameters is> 2.

func StrLen

func StrLen(s string) int

计算字符串长度

func StrSplitSkipEmpty

func StrSplitSkipEmpty(s string, sep byte, suggestcap int) []string

StrSplitSkipEmpty skip empty string suggestcap is suggest cap

func StrSplitSkipSpecNoEmpty

func StrSplitSkipSpecNoEmpty(s, spec string, sep byte, suggestcap int) []string

StrSplitSkipSpecNoEmpty todo

func StrToFloat64

func StrToFloat64(str string) float64

str 转为float64并

func Str_Pad

func Str_Pad(strs string, length int, pad string, up string) (str string)

补齐 strs 需要补齐字符串 length 补齐长度 pad 补齐的字符串 补齐方向 left左补齐;right右补齐

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

struct 转 map

func SubString

func SubString(str string, begin, length int) (substr string)

截取子串

func TagSplit

func TagSplit(keywords string) string

切割关键词为html片段

func ToLower

func ToLower(str string) string

大写转小写

func ToSha1

func ToSha1(s string) string

func ToUpper

func ToUpper(str string) string

小写转大写

func UrlDecode

func UrlDecode(urls string) string

urldecode

func UrlEncode

func UrlEncode(urls string) string

urlencode

func WriteAtFile

func WriteAtFile(fullpath, str string) error

字符串追加至文件

func WriteByteAtFile

func WriteByteAtFile(fullpath string, str []byte) error

字节追加至文件

func WriteByteFile

func WriteByteFile(fullpath string, data []byte) error

字节写入文件

func WriteFile

func WriteFile(fullpath, str string) error

字符串写入文件

Types

type Derivator

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

Derivator expand env engine

func NewDerivator

func NewDerivator() *Derivator

NewDerivator create env derivative

func (*Derivator) AddBashCompatible

func (de *Derivator) AddBashCompatible()

AddBashCompatible $0~$9

func (*Derivator) Append

func (de *Derivator) Append(k, v string) error

附加env

func (*Derivator) Environ

func (de *Derivator) Environ() []string

Environ create new environ block

func (*Derivator) EraseEnv

func (de *Derivator) EraseEnv(k string)

删除env k

func (*Derivator) ExpandEnv

func (de *Derivator) ExpandEnv(s string) string

展开env

func (*Derivator) GetEnv

func (de *Derivator) GetEnv(k string) string

获取env k

type Job

type Job func()

Job Represents user request, function which should be executed in some worker.

type RoutinePool

type RoutinePool struct {
	JobQueue chan Job

	NumberWorkers int
	// contains filtered or unexported fields
}

RoutinePool todo

func NewRoutinePool

func NewRoutinePool(numWorkers int, jobQueueLen int) *RoutinePool

NewRoutinePool Will make pool of gorouting workers. numWorkers - how many workers will be created for this pool queueLen - how many jobs can we accept until we block

Returned object contains JobQueue reference, which you can use to send job to pool.

func (*RoutinePool) JobDone

func (p *RoutinePool) JobDone()

JobDone In case you are using WaitAll fn, you should call this method every time your job is done.

If you are not using WaitAll then we assume you have your own way of synchronizing.

func (*RoutinePool) Release

func (p *RoutinePool) Release()

Release Will release resources used by pool

func (*RoutinePool) WaitAll

func (p *RoutinePool) WaitAll()

WaitAll Will wait for all jobs to finish.

func (*RoutinePool) WaitCount

func (p *RoutinePool) WaitCount(count int)

WaitCount How many jobs we should wait when calling WaitAll. It is using WaitGroup Add/Done/Wait

Directories

Path Synopsis
Package cedar-go implements double-array trie.
Package cedar-go implements double-array trie.
*
*
*
common
*
*
*
*
*
*
encry
Package geoip2 provides an easy-to-use API for the MaxMind GeoIP2 and GeoLite2 databases; this package does not support GeoIP Legacy databases.
Package geoip2 provides an easy-to-use API for the MaxMind GeoIP2 and GeoLite2 databases; this package does not support GeoIP Legacy databases.
Package gjson provides searching for json strings.
Package gjson provides searching for json strings.
grok module
Package guid defines a type for globally unique identifiers.
Package guid defines a type for globally unique identifiers.
*
alils
Package alils implements the SDK(v0.5.0) of Simple Log Service(abbr.
Package alils implements the SDK(v0.5.0) of Simple Log Service(abbr.
es
otp
Package otp implements both HOTP and TOTP based one time passcodes in a Google Authenticator compatible manner.
Package otp implements both HOTP and TOTP based one time passcodes in a Google Authenticator compatible manner.
interop Module
redis module
rsc
qr
Package qr encodes QR codes.
Package qr encodes QR codes.
qr/coding
Package coding implements low-level QR coding details.
Package coding implements low-level QR coding details.
scp
通过 SSH 复制文件
通过 SSH 复制文件
Go中文分词
Go中文分词
录像
录像
tcp
log
net
tencent
terminal
toml module
yaml module

Jump to

Keyboard shortcuts

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