util

package
v0.0.0-...-3842ff9 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Atoi

func Atoi(v string, defaultValue int) int

func Cut

func Cut(s, sep string) (a, b string)

Cut cuts the s into two ones.

func Env

func Env(name ...string) string

func EnvDuration

func EnvDuration(name string, defaultValue time.Duration) time.Duration

func ErrorString

func ErrorString(err error) string

ErrorString returns the error string, err can be nil.

func FileExists

func FileExists(name string) bool

func FindFreePort

func FindFreePort(ip string, port int) int

func Go

func Go(wg *sync.WaitGroup, f func())

Go 开始一个协程

func GoChan

func GoChan[T any](ctx context.Context, wg *sync.WaitGroup, ch <-chan T, f func(elem T) error)

GoChan 开始一个协程,从 ch 读取数据,调用 f 进行处理

func IsDir

func IsDir(dirInput string) bool

IsDir - Check if input path is a directory

func IsPortFree

func IsPortFree(ip string, port int) bool

func OrSlice

func OrSlice(a, b map[string]string) map[string]string

func Pick1

func Pick1[T any](s T, _ ...any) T

func RandPort

func RandPort(ip string, defaultPort int) int

func RemoveCreateDir

func RemoveCreateDir(folderPath string) error

RemoveCreateDir - create a directory structure, if still exist -> delete it before

func Think

func Think(thinkTime, reason string)

Think sleeps for a duration by envValue.

Types

type DelayWorker

type DelayWorker[T any] struct {
	// contains filtered or unexported fields
}

func NewDelayWorker

func NewDelayWorker[T any](wg *sync.WaitGroup, ctx context.Context, delayInterval time.Duration, fn func(value T, t time.Time)) *DelayWorker[T]

func (*DelayWorker[T]) Notify

func (s *DelayWorker[T]) Notify(t T)

type UniqueQueue

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

func NewUniqueQueue

func NewUniqueQueue(maxQueueSize int) *UniqueQueue

func (*UniqueQueue) Get

func (q *UniqueQueue) Get() []string

func (*UniqueQueue) Put

func (q *UniqueQueue) Put(value string)

Jump to

Keyboard shortcuts

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