utils

package
v0.0.0-...-06bcc1c Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 34 Imported by: 17

Documentation

Index

Constants

View Source
const (

	// DefaultVersion for default version
	DefaultVersion = "latest"
)

Variables

This section is empty.

Functions

func AdvancedDivide

func AdvancedDivide[T numbers](a, b T) T

AdvancedDivide returns 0 when 0/0

func Any

func Any[T any](slice []T, f func(T) bool) bool

Any returns true if any element in slice meets the requirement

func Bool2Int

func Bool2Int(a bool) int

func CleanStatsdMetrics

func CleanStatsdMetrics(k string) string

CleanStatsdMetrics trans dot to _

func DecodeMetaInLabel

func DecodeMetaInLabel(ctx context.Context, labels map[string]string) *types.LabelMeta

DecodeMetaInLabel get meta from label and decode it

func DecodePublishInfo

func DecodePublishInfo(info map[string]string) map[string][]string

DecodePublishInfo decode publish info

func EncodeMetaInLabel

func EncodeMetaInLabel(ctx context.Context, meta *types.LabelMeta) string

EncodeMetaInLabel encode meta to json

func EncodePublishInfo

func EncodePublishInfo(info map[string][]string) map[string]string

EncodePublishInfo encode publish info

func EnsureReaderClosed

func EnsureReaderClosed(ctx context.Context, stream io.ReadCloser)

EnsureReaderClosed As the name says, blocks until the stream is empty, until we meet EOF

func Filter

func Filter[T any](slice []T, f func(T) bool) []T

Filter returns a new slice with elements that meet the requirement

func GenerateSlice

func GenerateSlice[T any](l int, factory func() T) []T

GenerateSlice generates a slice with factory function

func GetGitRepoName

func GetGitRepoName(url string) (string, error)

GetGitRepoName return git repo name

func GetHTTPClient

func GetHTTPClient() *http.Client

GetHTTPClient returns a HTTP client

func GetHTTPSClient

func GetHTTPSClient(ctx context.Context, certPath, name, ca, cert, key string) (client *http.Client, err error)

GetHTTPSClient returns an HTTPS client if cert_path/ca/cert/key is empty, it returns an HTTP client instead

func GetOutboundAddress

func GetOutboundAddress(bind string, probeTarget string) (string, error)

GetOutboundAddress finds out self-service address

func GetTag

func GetTag(image string) string

GetTag reture image tag

func GetUnixSockClient

func GetUnixSockClient() *http.Client

GetUnixSockClient .

func InheritTracingInfo

func InheritTracingInfo(ctx, newCtx context.Context) context.Context

InheritTracingInfo pass through the tracing info: peer, tracing id

func LabelsFilter

func LabelsFilter(extend map[string]string, labels map[string]string) bool

LabelsFilter filter workload by labels

func ListAllExecutableFiles

func ListAllExecutableFiles(basedir string) ([]string, error)

ListAllExecutableFiles returns all the executable files in the given path

func ListAllSharedLibFiles

func ListAllSharedLibFiles(basedir string) ([]string, error)

func LoadConfig

func LoadConfig(configPath string) (types.Config, error)

LoadConfig load config from yaml

func MakeCommandLineArgs

func MakeCommandLineArgs(s string) []string

MakeCommandLineArgs make command line args

func MakePublishInfo

func MakePublishInfo(networks map[string]string, ports []string) map[string][]string

MakePublishInfo generate publish info

func MakeWorkloadName

func MakeWorkloadName(appname, entrypoint, ident string) string

MakeWorkloadName joins appname, entrypoint, ident using '_'

func Map

func Map[T1, T2 any](slice []T1, f func(T1) T2) []T2

Map like map in Python

func Max

func Max[T constraints.Ordered](x T, xs ...T) T

Max returns the biggest one.

func MergeHookOutputs

func MergeHookOutputs(outputs []*bytes.Buffer) []byte

MergeHookOutputs merge hooks output

func Min

func Min[T constraints.Ordered](x T, xs ...T) T

Min returns the lesser one.

func NewInheritCtx

func NewInheritCtx(ctx context.Context) context.Context

NewInheritCtx new a todo context and get the previous values

func NewPool

func NewPool(max int) (*ants.PoolWithFunc, error)

NewPool new a pool

func NormalizeImageName

func NormalizeImageName(image string) string

NormalizeImageName will normalize image name

func PCR

func PCR(ctx context.Context, prepare func(ctx context.Context) error, commit func(ctx context.Context) error, rollback func(ctx context.Context) error, ttl time.Duration) error

PCR Prepare, Commit, Rollback. `prepare` should be a pure calculation process without side effects. `commit` writes the calculation result of `prepare` into database. if `commit` returns error, `rollback` will be performed.

func ParseRAMInHuman

func ParseRAMInHuman(ram string) (int64, error)

ParseRAMInHuman returns int value in bytes of a human readable string e.g. 100KB -> 102400

func ParseWorkloadName

func ParseWorkloadName(workloadName string) (string, string, string, error)

ParseWorkloadName does the opposite thing as MakeWorkloadName

func RandomString

func RandomString(n int) string

RandomString random a string

func Range

func Range(n int) (res []int)

Range .

func Reverse

func Reverse[T any](s []T)

Reverse any slice

func Round

func Round(f float64) float64

Round for float64 to int

func SHA256

func SHA256(input string) string

SHA256 .

func SentryGo

func SentryGo(f func())

SentryGo wraps goroutine spawn to capture panic

func ShortID

func ShortID(workloadID string) string

ShortID short workload ID

func Sum

func Sum[T numbers](slice []T) T

Sum returns sum of all elements in slice

func Tail

func Tail(path string) string

Tail return tail thing

func TempFile

func TempFile(stream io.ReadCloser) (string, error)

TempFile store a temp file

func Txn

func Txn(ctx context.Context, cond contextFunc, then contextFunc, rollback func(context.Context, bool) error, ttl time.Duration) (txnErr error)

Txn provides unified API to perform txn

func Unique

func Unique[T, E constraints.Ordered](s []T, getVal func(int) E) (j int)

Unique return a index, where s[:index] is a unique slice Unique requires sorted slice

func WithTimeout

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

WithTimeout runs a function with given timeout

Types

type EngineCache

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

EngineCache connections otherwise they'll leak

func NewEngineCache

func NewEngineCache(expire time.Duration, cleanupInterval time.Duration) *EngineCache

NewEngineCache creates Cache instance

func (*EngineCache) Delete

func (c *EngineCache) Delete(host string, _ ...string)

Delete connection by host

func (*EngineCache) Get

func (c *EngineCache) Get(endpoint string) engine.API

Get connection by host

func (*EngineCache) Set

func (c *EngineCache) Set(endpoint string, client engine.API)

Set connection with host

Jump to

Keyboard shortcuts

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