utils

package
v0.0.0-...-b022d11 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: MIT Imports: 30 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Pool *ants.Pool

Pool .

Functions

func BackoffRetry

func BackoffRetry(ctx context.Context, maxAttempts int, f func() error) error

BackoffRetry retries up to `maxAttempts` times, and the interval will grow exponentially

func CheckHTTP

func CheckHTTP(ctx context.Context, ID string, backends []string, code int, timeout time.Duration) bool

CheckHTTP 检查一个workload的所有URL CheckHTTP 事实上一般也就一个

func CheckTCP

func CheckTCP(ctx context.Context, ID string, backends []string, timeout time.Duration) bool

CheckTCP 检查一个TCP 这里不支持ctx?

func GetAppInfo

func GetAppInfo(containerName string) (name, entrypoint, ident string, err error)

GetAppInfo return app info

func GetDevicePath

func GetDevicePath(major, minor uint64) (devPath string, err error)

func GetIP

func GetIP(daemonHost string) string

GetIP Get hostIP

func GetMaxAttemptsByTTL

func GetMaxAttemptsByTTL(ttl int64) int

GetMaxAttemptsByTTL .

func IsDockerized

func IsDockerized() bool

IsDockerized returns if the agent is running in docker

func MakeDockerClient

func MakeDockerClient(config *types.Config) (*engineapi.Client, error)

MakeDockerClient make a docker client

func MakeYavirtClient

func MakeYavirtClient(config *types.Config) (yavirtclient.Client, error)

MakeYavirtClient make a yavirt client

func NewBufPipe

func NewBufPipe(bufCap int64) (*PipeReader, *PipeWriter)

NewBufPipe creates a synchronous pipe with capacity

func ReplaceNonUtf8

func ReplaceNonUtf8(str string) string

ReplaceNonUtf8 replaces non-utf8 characters in \x format.

func UseLabelAsFilter

func UseLabelAsFilter() bool

UseLabelAsFilter return if use label as filter

func WithTimeout

func WithTimeout(ctx context.Context, timeout time.Duration, f func(ctx2 context.Context))

WithTimeout runs a function with given timeout

func WritePid

func WritePid(path string)

WritePid write pid

Types

type GroupCAS

type GroupCAS struct {
	*haxmap.Map[string, struct{}]
}

GroupCAS indicates cas locks which are grouped by keys.

func NewGroupCAS

func NewGroupCAS() *GroupCAS

NewGroupCAS .

func (*GroupCAS) Acquire

func (g *GroupCAS) Acquire(key string) (free func(), acquired bool)

Acquire tries to acquire a cas lock.

type HashBackends

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

HashBackends is a simple hash backend

func NewHashBackends

func NewHashBackends(data []string) *HashBackends

NewHashBackends new a hash backends

func (*HashBackends) Get

func (s *HashBackends) Get(v string, offset int) string

Get get a backend

func (*HashBackends) Len

func (s *HashBackends) Len() uint32

Len get len of backends

type PipeReader

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

A PipeReader is the read half of a pipe.

func (*PipeReader) Close

func (r *PipeReader) Close() error

Close closes the reader

func (*PipeReader) CloseWithError

func (r *PipeReader) CloseWithError(err error) error

CloseWithError closes the reader; subsequent writes to the write half of the pipe will return the error err.

func (*PipeReader) Read

func (r *PipeReader) Read(data []byte) (int, error)

Read implements the standard Read interface

type PipeWriter

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

A PipeWriter is the write half of a pipe.

func (*PipeWriter) Close

func (w *PipeWriter) Close() error

Close closes the writer

func (*PipeWriter) CloseWithError

func (w *PipeWriter) CloseWithError(err error) error

CloseWithError closes the writer

func (*PipeWriter) Write

func (w *PipeWriter) Write(data []byte) (int, error)

Write implements the standard Write interface: discard if current length exceeds capacity

type RetryTask

type RetryTask struct {
	Func        func() error
	MaxAttempts int
	// contains filtered or unexported fields
}

RetryTask .

func NewRetryTask

func NewRetryTask(ctx context.Context, maxAttempts int, f func() error) *RetryTask

NewRetryTask .

func (*RetryTask) Run

func (r *RetryTask) Run(ctx context.Context) error

Run start running retry task

func (*RetryTask) Stop

func (r *RetryTask) Stop(context.Context)

Stop stops running task

Jump to

Keyboard shortcuts

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