utils

package
v0.14.4-dev.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: AGPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Timing []timeLog

Functions

func BuildRequestPayload added in v0.2.0

func BuildRequestPayload(signature string, payload map[string]interface{}) *bytes.Buffer

BuildRequestPayload :: merges the provided payload with the standard payload that needs to be sent

func CombineErrors added in v0.6.0

func CombineErrors(errors ...error) error

func CombineErrorsWithPrefix added in v0.6.0

func CombineErrorsWithPrefix(prefix string, errors ...error) error

func CtyToGo added in v0.14.0

func CtyToGo(v cty.Value) (val interface{}, err error)

func CtyToJSON added in v0.14.0

func CtyToJSON(val cty.Value) (string, error)

CtyToJSON converts a cty value to it;s JSON representation

func CtyToPostgresString added in v0.14.0

func CtyToPostgresString(v cty.Value) (valStr string, err error)

CtyToPostgresString convert a cty value into a postgres representation of the value

func CtyToString added in v0.14.0

func CtyToString(v cty.Value) (valStr string, err error)

CtyToString convert a cty value into a string representation of the value

func CtyTypeToHclType added in v0.14.0

func CtyTypeToHclType(types ...cty.Type) string

CtyTypeToHclType converts a cty type to a hcl type accept multiple types and use the first non null and non dynamic one

func DebugDumpJSON added in v0.3.0

func DebugDumpJSON(msg string, d interface{})

functions specifically used for Debugging purposes.

func DebugDumpRows added in v0.11.0

func DebugDumpRows(rows *sql.Rows)

func DebugDumpViper added in v0.3.0

func DebugDumpViper()

func DisplayProfileData

func DisplayProfileData()

func EnsureDirectoryPermission added in v0.7.0

func EnsureDirectoryPermission(directoryPath string) error

func FailOnError

func FailOnError(err error)

func FailOnErrorWithMessage

func FailOnErrorWithMessage(err error, message string)

func FileHash

func FileHash(filePath string) (string, error)

func FileModTime added in v0.11.0

func FileModTime(filePath string) (time.Time, error)

func Filter added in v0.14.0

func Filter[V any](elements []V, predicate func(V) bool) []V

Filter returns a new slice only containing the elements for which invoking the predicate returned true

The predicate is invoked with each element

func FindProcess added in v0.10.0

func FindProcess(targetPid int) (*psutils.Process, error)

FindProcess tries to find the process with the given pid returns nil if the process could not be found

func GetMD5Hash added in v0.8.0

func GetMD5Hash(text string) string

func HandleCancelError added in v0.7.0

func HandleCancelError(err error) error

HandleCancelError modifies a context.Canceled error into a readable error that can be printed on the console

func IsCancelledError added in v0.8.0

func IsCancelledError(err error) bool

func IsContextCancelled added in v0.8.0

func IsContextCancelled(ctx context.Context) bool

func IsPortBindable added in v0.13.0

func IsPortBindable(port int) error

func IsWSL added in v0.2.0

func IsWSL() (bool, error)

IsWSL :: detects whether app is running in WSL environment refer to: https://github.com/Microsoft/WSL/issues/423#issuecomment-679190758

func LocalAddresses added in v0.13.0

func LocalAddresses() ([]string, error)

func LogTime

func LogTime(operation string)

func Map added in v0.14.2

func Map[V any, M any](elements []V, mapper func(V) M) []M

Map returns a new slice where every value is mapped to a new value through the mapper

The mapper is invoked with each element

func MergeStringMaps added in v0.13.0

func MergeStringMaps(old, new map[string]string) map[string]string

MergeStringMaps merges 'new' onto old. Any vakue existing in new but not old is added to old NOTE this mutates old

func MoveFile added in v0.14.0

func MoveFile(source string, destination string) error

MoveFile moves a file from source to destiantion.

It first attempts the movement using OS primitives (os.Rename)
If os.Rename fails, it copies the file byte-by-byte to the destination and then removes the source

func Partition added in v0.14.0

func Partition[V any](elements []V, predicate func(V) bool) ([]V, []V)

Partition splits the array of elements into two groups: the left partition contains elements that the predicate returns `true` for. the right partition contains elements that the predicate returns `false` for.

The predicate is invoked with each element

func PidExists added in v0.10.0

func PidExists(targetPid int) (bool, error)

PidExists scans through the list of PIDs in the system and checks for the `targetPID`.

PidExists uses iteration, instead of signalling, since we have observed that signalling does not always work reliably when the destination of the signal is a child of the source of the signal - which may be the case then starting implicit services

func Pluralize added in v0.2.2

func Pluralize(base string, count int) string

Pluralize :: pluralizes a word (if applicable) based on provided count

func PrefixError added in v0.7.0

func PrefixError(err error, prefix string) error

func RemoveDirectoryContents added in v0.7.0

func RemoveDirectoryContents(removePath string) error

func SafeIntEqual added in v0.13.0

func SafeIntEqual(i1, i2 *int) bool

func SafeStringsEqual added in v0.13.0

func SafeStringsEqual(s1, s2 interface{}) bool

func SendRequest added in v0.2.0

func SendRequest(signature string, method string, sendRequestTo url.URL, payload *bytes.Buffer) (*http.Response, error)

SendRequest ::

func ShowError

func ShowError(ctx context.Context, err error)

func ShowErrorWithMessage

func ShowErrorWithMessage(ctx context.Context, err error, message string)

ShowErrorWithMessage displays the given error nicely with the given message

func ShowWarning

func ShowWarning(warning string)

func SortedStringKeys added in v0.14.0

func SortedStringKeys[V any](m map[string]V) []string

func SplitByRune added in v0.10.0

func SplitByRune(str string, r rune) []string

SplitByRune uses the CSV decoder to parse out the tokens - even if they are quoted and/or escaped

func SplitByWhitespace added in v0.10.0

func SplitByWhitespace(str string) []string

SplitByWhitespace splits by the ' ' rune

func StringHash

func StringHash(s string) uint32

func StringSliceDistinct added in v0.12.0

func StringSliceDistinct(slice []string) []string

TODO: investigate turbot/go-kit/helpers

func ToIntegerPointer added in v0.13.0

func ToIntegerPointer(i int) *int

ToIntegerPointer converts an integer into its pointer

func ToStringPointer added in v0.5.0

func ToStringPointer(s string) *string

ToStringPointer converts a string into its pointer

func TransformErrorToSteampipe added in v0.6.0

func TransformErrorToSteampipe(err error) error

TransformErrorToSteampipe removes the pq: and rpc error prefixes along with all the unnecessary information that comes from the drivers and libraries

func UnderlyingArch added in v0.14.0

func UnderlyingArch() (string, error)

UnderlyingArch detects the underlying architecture(amd64/arm64) of the system we need this to detect the underlying architecture to install the correct FDW package

Types

type ExitCode

type ExitCode int

ExitCode :: alias for exitcode

type FileWatcher added in v0.4.0

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

func NewWatcher added in v0.4.0

func NewWatcher(opts *WatcherOptions) (*FileWatcher, error)

func (*FileWatcher) Close added in v0.4.0

func (w *FileWatcher) Close()

func (*FileWatcher) Start added in v0.10.0

func (w *FileWatcher) Start()

type InteractiveExitStatus

type InteractiveExitStatus struct {
	// TODO remove altogether
	ExitCode int
}

InteractiveExitStatus :: exist status from the interative prompt

We exit go-prompt after every query (in order to manage the prompt history to only include complete queries) We therefore need to distinguish between:

a user requested exit (ctrl+D or .exit) - indicated by a non-nil exit code and restart=false and a value , go-prompt being terminated after a query completion and requiring restarting - indicated by restart=true

type LifecycleEvent added in v0.10.0

type LifecycleEvent struct {
	Event string
	Time  time.Time
}

type LifecycleTimer added in v0.10.0

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

LifecycleTimer records the time for lifecycle events

func NewLifecycleTimer added in v0.10.0

func NewLifecycleTimer() *LifecycleTimer

func (*LifecycleTimer) Add added in v0.10.0

func (r *LifecycleTimer) Add(event string)

func (LifecycleTimer) GetDuration added in v0.10.0

func (r LifecycleTimer) GetDuration() time.Duration

GetDuration returns the duration between first and the last event

type WatcherOptions added in v0.4.0

type WatcherOptions struct {
	Directories []string
	Include     []string
	Exclude     []string
	OnChange    func([]fsnotify.Event)
	OnError     func(error)
	ListFlag    filehelpers.ListFlag
}

Jump to

Keyboard shortcuts

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