gitee

package module
v0.7.9 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 18 Imported by: 0

README

Gitee golang standard components

用来存放Gitee内部使用的golang小工具

包含字符串处理,服务器相关等

安装

go get https://gitee.com/oscstudio/gitee

引入

import "gitee.com/oscstudio/gitee"

使用示例

// "hello, world!"
gitee.StrCat("hello, ", "world!") 

// path is exists?
gitee.PathExists("/tmp/gitee")

主要文件介绍

序号 文件 主要用途
0 conversion.go 计量单位相关
1 daemonize.go 守护进程相关
2 env.go 环境变量相关
3 exserver 平滑重启等
4 fs.go 文件操作相关
5 parseargv.go 执行参数相关
6 pathnode.go path_with_namespace相关
7 routinepool.go routinepool相关
8 strings.go 字符串处理相关
9 uuid.go uuid生成相关

Documentation

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

View Source
const (
	REQUIRED int = iota
	NOARG
	OPTIONAL
)

TODO

Variables

View Source
var (
	ErrPendingOverFlow = errors.New("Pending queue overflowed, please try again later")
	ErrPendingTimeout  = errors.New("Pending timeout, please try again later")
)
View Source
var (
	ErrNilArgv       = errors.New("argv is nil")
	ErrUnExpectedArg = errors.New("unexpected argument '-'")
)

error

Functions

func AppDaemonizedEx

func AppDaemonizedEx(name, pidfile, stderr string) error

AppDaemonizedEx todo

func AppDir

func AppDir() string

AppDir todo

func AppExit

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

AppExit exit app

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

AppRestart restart app

func ByteCat added in v0.5.2

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

ByteCat return bytes.

func ErrorCat added in v0.5.3

func ErrorCat(sv ...string) error

ErrorCat todo

func EscapeNonBmpRune

func EscapeNonBmpRune(s string) string

EscapeNonBmpRune escape non BMP rune

func FileIsOpened added in v0.7.9

func FileIsOpened(path string) bool

func HasNonBmpRune

func HasNonBmpRune(s string) bool

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

func IsPathReachable

func IsPathReachable(s string) bool

IsPathReachable path reachable

func MakeError added in v0.6.0

func MakeError(sv ...string) error

MakeError todo

func Maximum64 added in v0.5.3

func Maximum64(x, y int64) int64

Maximum64 todo

func Minimum64 added in v0.5.3

func Minimum64(x, y int64) int64

Minimum64 todo

func NewAppRestart added in v0.6.6

func NewAppRestart(name, pidfile string) error

new app restart only send SIGUSR2

func NewUUID

func NewUUID() (string, error)

NewUUID create v4 uuid More powerful UUID libraries can be used: https://github.com/google/uuid

func PathDirExists added in v0.5.4

func PathDirExists(p string) bool

PathDirExists todo

func PathExists added in v0.5.4

func PathExists(p string) bool

PathExists path exists

func PathNodeCanonicalize

func PathNodeCanonicalize(u string) string

PathNodeCanonicalize todo

func PathNodeCanonicalizeStrict added in v0.5.6

func PathNodeCanonicalizeStrict(u string) string

PathNodeCanonicalizeStrict todo

func PathSplit added in v0.5.7

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

PathSplit split path and

func ReadFileFirstLine

func ReadFileFirstLine(path string) (string, error)

ReadFileFirstLine read file first line

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 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 WarpError added in v0.6.0

func WarpError(err error, sv ...string) error

WarpError todo

Types

type ArgvContainer

type ArgvContainer interface {
	Invoke(val int, oa, raw string) error
}

ArgvContainer todo

type ArgvEngine

type ArgvEngine struct {
	SubcmdMode bool // subcmd mode
	// contains filtered or unexported fields
}

ArgvEngine todo

func (*ArgvEngine) Add

func (ae *ArgvEngine) Add(name string, ha, val int)

Add option

func (*ArgvEngine) Execute

func (ae *ArgvEngine) Execute(argv []string, ac ArgvContainer) error

Execute todo

func (*ArgvEngine) Unresolved

func (ae *ArgvEngine) Unresolved() []string

Unresolved todo

type Derivator added in v0.2.0

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

Derivator expand env engine

func NewDerivator added in v0.2.0

func NewDerivator() *Derivator

NewDerivator create env derivative

func (*Derivator) AddBashCompatible added in v0.2.0

func (de *Derivator) AddBashCompatible()

AddBashCompatible $0~$9

func (*Derivator) Append added in v0.2.0

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

Append append to env

func (*Derivator) Environ added in v0.4.3

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

Environ create new environ block

func (*Derivator) EraseEnv added in v0.5.1

func (de *Derivator) EraseEnv(k string)

EraseEnv k

func (*Derivator) ExpandEnv added in v0.2.0

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

ExpandEnv env

func (*Derivator) GetEnv added in v0.2.0

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

GetEnv env

type Job added in v0.5.5

type Job func()

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

type Limiter added in v0.7.1

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

func NewLimiter added in v0.7.1

func NewLimiter(max, maxPending int64) *Limiter

return a new rate limiter instance.

params:

max: Number of processing tasks
maxPending: Number of pending tasks after processing tasks is overflowed

func (*Limiter) Limit added in v0.7.4

func (l *Limiter) Limit(ctx context.Context, task TaskFunc) error

Run task with rate limit

func (*Limiter) Pending added in v0.7.2

func (l *Limiter) Pending() int64

return number of pending tasks

func (*Limiter) Processing added in v0.7.1

func (l *Limiter) Processing() int64

return number of processing tasks

func (*Limiter) ProcessingAndPending added in v0.7.2

func (l *Limiter) ProcessingAndPending() int64

return number of processing and pending tasks

func (*Limiter) SetMaxPending added in v0.7.4

func (l *Limiter) SetMaxPending(maxPending int64)

Set the maximum number of pending tasks

func (*Limiter) SetMaxProcessing added in v0.7.4

func (l *Limiter) SetMaxProcessing(maxProcessing int64)

Set the maximum number of processing tasks

type RoutinePool added in v0.5.5

type RoutinePool struct {
	JobQueue chan Job

	NumberWorkers int
	// contains filtered or unexported fields
}

RoutinePool todo

func NewRoutinePool added in v0.5.5

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 added in v0.5.5

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 added in v0.5.5

func (p *RoutinePool) Release()

Release Will release resources used by pool

func (*RoutinePool) WaitAll added in v0.5.5

func (p *RoutinePool) WaitAll()

WaitAll Will wait for all jobs to finish.

func (*RoutinePool) WaitCount added in v0.5.5

func (p *RoutinePool) WaitCount(count int)

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

type TaskFunc added in v0.7.4

type TaskFunc func() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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