utils

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDNS

func CheckDNS(domain string) errors.Error

CheckDNS FIXME ...

func CheckNetwork

func CheckNetwork(host, port string, timeout time.Duration) errors.Error

CheckNetwork FIXME ...

func CreateCmd added in v0.15.0

func CreateCmd(args ...string) *exec.Cmd

CreateCmd wraps the args in "sh -c" for shell-level execution

func CreateGZipArchive added in v0.14.0

func CreateGZipArchive(archivePath string, sourcePaths ...string) errors.Error

CreateGZipArchive creates a tar archive, compresses it with gzip and writes the files/directories associated with the `sourcePaths` to it. If a sourcePath directory ends with /*, then its contents are copied over, but not the directory itself

func CreateZipArchive added in v0.14.0

func CreateZipArchive(archivePath string, sourcePaths ...string) errors.Error

CreateZipArchive creates a zip archive and writes the files/directories associated with the `sourcePaths` to it. If a sourcePath directory ends with /*, then its contents are copied over, but not the directory itself

func GatherCallFrames

func GatherCallFrames(delta int) string

GatherCallFrames FIXME ...

func GetEncodedToken

func GetEncodedToken(username string, password string) string

GetEncodedToken FIXME ...

func RecoverToError added in v0.15.0

func RecoverToError() error

RecoverToError call the recover to catch the panic and changed it to be an error

func ResolvePort

func ResolvePort(port string, schema string) (string, errors.Error)

ResolvePort FIXME ...

func SliceRemove added in v0.15.0

func SliceRemove[T ~int | ~string](source []T, toRemoves ...T) []T

SliceRemove remove some items in old slice

func StrToBoolOr added in v0.12.0

func StrToBoolOr(text string, defaultValue bool) (bool, errors.Error)

StrToBoolOr Return defaultValue if text is empty, or try to convert it to bool

func StrToDurationOr

func StrToDurationOr(text string, defaultValue time.Duration) (time.Duration, errors.Error)

StrToDurationOr Return defaultValue if text is empty, or try to convert it to time.Duration

func StrToIntOr

func StrToIntOr(text string, defaultValue int) (int, errors.Error)

StrToIntOr Return defaultValue if text is empty, or try to convert it to int

func StreamProcess added in v0.15.0

func StreamProcess[T any](cmd *exec.Cmd, converter func(b []byte) (T, error)) (<-chan *ProcessResponse[T], error)

StreamProcess runs the cmd and returns its standard output on a line-by-line basis, on a channel. The converter functor will allow you to convert the incoming raw to your custom data type T. This is a nonblocking function.

func StringsContains added in v0.12.0

func StringsContains(slice []string, target string) bool

StringsContains checks if `source` String Slice contains `target` string

func StringsUniq added in v0.12.0

func StringsUniq(source []string) []string

StringsUniq returns a new String Slice contains deduped elements from `source`

func WalkFields added in v0.12.0

func WalkFields(t reflect.Type, filter func(field *reflect.StructField) bool) (f []reflect.StructField)

WalkFields get the field data by tag

Types

type ProcessResponse added in v0.15.0

type ProcessResponse[T any] struct {
	Data T
	Err  error
}

ProcessResponse wraps output of a process

func RunProcess added in v0.15.0

func RunProcess(cmd *exec.Cmd) (*ProcessResponse[[]byte], error)

RunProcess runs the cmd and returns its raw standard output. This is a blocking function.

Jump to

Keyboard shortcuts

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