util

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	StateRunning uint32 = 0
	StateStopped uint32 = 1
)

Variables

View Source
var (
	GlobalTimerWheel  *goetty.TimeoutWheel //the global timer wheel
	GlobalParsingPool *WorkerPool          //for all tasks' parsing, cpu intensive
	GlobalWritingPool *WorkerPool          //the all tasks' writing ClickHouse, cpu-net balance
	Logger            *zap.Logger
)
View Source
var (
	// ErrStopped when stopped
	ErrStopped = errors.New("WorkerPool already stopped")
)

Functions

func EnvBoolVar added in v1.5.2

func EnvBoolVar(value *bool, key string)

func EnvIntVar added in v1.5.2

func EnvIntVar(value *int, key string)

func EnvStringVar added in v1.5.2

func EnvStringVar(value *string, key string)

func GetIP4Byname added in v1.5.2

func GetIP4Byname(host string) (ips []string, err error)

func GetOutboundIP added in v1.5.2

func GetOutboundIP() (ip net.IP, err error)

GetOutboundIP get preferred outbound ip of this machine https://stackoverflow.com/questions/23558425/how-do-i-get-the-local-ip-address-in-go

func GetShift added in v1.5.2

func GetShift(s int) (shift uint)

GetShift returns the smallest `shift` which 1<<shift is no smaller than s

func GetSourceName added in v1.5.2

func GetSourceName(name string) (sourcename string)

GetSourceName returns the field name in message for the given ClickHouse column

func GetSpareTCPPort added in v1.5.2

func GetSpareTCPPort(portBegin int) (port int)

GetSpareTCPPort find a spare TCP port

func InitGlobalParsingPool added in v1.5.2

func InitGlobalParsingPool()

InitGlobalParsingPool initialize GlobalParsingPool

func InitGlobalTimerWheel added in v1.5.2

func InitGlobalTimerWheel()

InitGlobalTimerWheel initialize the global timer wheel

func InitGlobalWritingPool added in v1.5.2

func InitGlobalWritingPool(maxWorkers int)

InitGlobalWritingPool initialize GlobalWritingPool

func InitLogger added in v1.5.2

func InitLogger(newLogPaths []string)

func JksToPem added in v1.5.2

func JksToPem(jksPath, jksPassword string, overwrite bool) (certPemPath, keyPemPath string, err error)

JksToPem converts JKS to PEM Refers to: https://serverfault.com/questions/715827/how-to-generate-key-and-crt-file-from-jks-file-for-httpd-apache-server

func Run added in v1.5.2

func Run(appName string, initFunc, jobFunc, cleanupFunc func() error)

func SetLogLevel added in v1.5.2

func SetLogLevel(newLogLevel string)

func StringContains

func StringContains(arr []string, str string) bool

StringContains check if contains string in array

func WaitForExitSign added in v1.5.2

func WaitForExitSign()

Types

type WorkerPool added in v1.5.2

type WorkerPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

WorkerPool is a blocked worker pool inspired by https://github.com/gammazero/workerpool/

func NewWorkerPool added in v1.5.2

func NewWorkerPool(maxWorkers int, queueSize int) *WorkerPool

New creates and starts a pool of worker goroutines.

func (*WorkerPool) Resize added in v1.5.2

func (w *WorkerPool) Resize(maxWorkers int)

Resize ensures worker number match the expected one.

func (*WorkerPool) Restart added in v1.5.2

func (w *WorkerPool) Restart()

func (*WorkerPool) StopWait added in v1.5.2

func (w *WorkerPool) StopWait()

StopWait stops the worker pool and waits for all queued tasks tasks to complete.

func (*WorkerPool) Submit added in v1.5.2

func (w *WorkerPool) Submit(fn func()) (err error)

Submit enqueues a function for a worker to execute. Submit will block regardless if there is no free workers.

Jump to

Keyboard shortcuts

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