utils

package
v0.0.0-...-7d3b672 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 Imports: 29 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 Convert

func Convert[T any](value any) (T, errors.Error)

Convert converts value to type T. If value is a slice, it converts each element of the slice to type T. Does not support nested slices.

func CreateCmd

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

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

func CreateGZipArchive

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

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 GetItem

func GetItem[T any](array JsonArray, index int) (T, errors.Error)

func GetProperty

func GetProperty[T any](object JsonObject, key string) (T, errors.Error)

func RandLetterBytes

func RandLetterBytes(n int) (string, errors.Error)

RandLetterBytes returns a cryptographically secure random string with given length n

func RecoverToError

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

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

SliceRemove remove some items in old slice

func StrToBoolOr

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 StringsContains

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

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

func StringsUniq

func StringsUniq(source []string) []string

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

func WalkFields

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

WalkFields get the field data by tag

Types

type JsonArray

type JsonArray = []any

type JsonObject

type JsonObject = map[string]any

type ProcessResponse

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

ProcessResponse wraps output of a process

func RunProcess

func RunProcess(cmd *exec.Cmd, opts *RunProcessOptions) (*ProcessResponse, errors.Error)

RunProcess runs the cmd and blocks until its completion. All returned results will have type []byte.

func (*ProcessResponse) GetError

func (resp *ProcessResponse) GetError() errors.Error

GetError gets the error on the response

func (*ProcessResponse) GetFdOut

func (resp *ProcessResponse) GetFdOut() []byte

func (*ProcessResponse) GetStderr

func (resp *ProcessResponse) GetStderr() []byte

func (*ProcessResponse) GetStdout

func (resp *ProcessResponse) GetStdout() []byte

type ProcessStream

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

ProcessStream wraps output of a process

func StreamProcess

func StreamProcess(cmd *exec.Cmd, opts *StreamProcessOptions) (*ProcessStream, errors.Error)

StreamProcess runs the cmd and returns its 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 (*ProcessStream) Cancel

func (p *ProcessStream) Cancel() errors.Error

Cancel cancels the stream by sending a termination signal to the target.

func (*ProcessStream) Receive

func (p *ProcessStream) Receive() <-chan *ProcessResponse

Receive listens to the process retrieval channel

type RunProcessOptions

type RunProcessOptions struct {
	OnStdout func(b []byte)
	OnStderr func(b []byte)
	UseFdOut bool
	OnFdOut  func(b []byte)
}

RunProcessOptions options for running a process

type StreamProcessOptions

type StreamProcessOptions struct {
	OnStdout func(b []byte)
	OnStderr func(b []byte)
	// UseFdOut if true, it'll open this fd to be used by the child process. Useful to isolate stdout and custom outputs
	UseFdOut bool
	OnFdOut  func(b []byte)
}

StreamProcessOptions options for streaming a process

type TableInfoChecker

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

func NewTableInfoChecker

func NewTableInfoChecker(cfg TableInfoCheckerConfig) *TableInfoChecker

func (*TableInfoChecker) FeedIn

func (checker *TableInfoChecker) FeedIn(modelsDir string, f func() []dal.Tabler, additionalIgnorablePackages ...string)

The FeedIn function iterates through the model definitions, identifies all the tables by parsing the source files, and then compares them with the output obtained from the GetTablesInfo function. If the plugin has no models directory, pass in the root directory of the plugin

func (*TableInfoChecker) Verify

func (checker *TableInfoChecker) Verify() errors.Error

type TableInfoCheckerConfig

type TableInfoCheckerConfig struct {
	TablePrefix         string
	ValidatePluginCount bool
	IgnoreTables        []string
}

Jump to

Keyboard shortcuts

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