gsmhelpers

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: GPL-3.0 Imports: 17 Imported by: 1

Documentation

Overview

Package gsmhelpers contains helper functions to GSM

Index

Constants

This section is empty.

Variables

View Source
var RetryOn []int

RetryOn defines the HTTP error codes that should be retried on. Note that GSM will always attempt to retry on a 403 error code with a message that indicates a quota / rate limit error

Functions

func ActionRetry

func ActionRetry(errKey string, c func() error) (bool, error)

ActionRetry performs an action that does not return an object, retrying on failure when appropriate

func Contains

func Contains[T comparable](value T, slice []T) bool

Contains checks if a value is inside a slice

func EnsurePrefix added in v0.8.0

func EnsurePrefix(s, p string) string

func FlagToMap

func FlagToMap(value string) (m map[string]string)

FlagToMap first splits a string by ";" to get the attributes, then each attribute is split by "=" to get the key / value pair

func FlagsToMap

func FlagsToMap(flags *pflag.FlagSet) (m map[string]*Value)

FlagsToMap converts all flags to a map

func FormatErrorKey

func FormatErrorKey(s ...string) string

FormatErrorKey formats an error key. Error keys are used on error messages to make it easier to debug where an error occurred

func GetAllFlags

func GetAllFlags(flags map[string]*Flag) map[string]*Flag

GetAllFlags creates copies of all normal flags with the _ALL suffix. These flags are used for batch commands where normal flags get converted to int64 flags that are used to reference columns in CSV files

func GetBatchMaps

func GetBatchMaps(cmd *cobra.Command, cmdFlags map[string]*Flag) (<-chan map[string]*Value, error)

GetBatchMaps returns a channel containing maps to be used for batch requests to the Google API

func GetCSVContent

func GetCSVContent(path string, delimiter rune, skipHeader bool) ([][]string, error)

GetCSVContent gets the content of a CSV file as [][]string

func GetFileContentAsString

func GetFileContentAsString(path string) (string, error)

GetFileContentAsString returns the content of a file as a string

func GetJSONEncoder added in v0.2.1

func GetJSONEncoder(indent bool) *json.Encoder

GetJSONEncoder returns a new json encoder

func GetObjectRetry

func GetObjectRetry(errKey string, c func() (any, error)) (any, error)

GetObjectRetry performs an action that returns an object, retrying on failure when appropriate

func InitBatchCommand

func InitBatchCommand(parentCmd, childCmd *cobra.Command, cmdFlags, cmdAllFlags, batchFlags map[string]*Flag)

InitBatchCommand sets flags for a batch command appropriately

func InitCommand

func InitCommand(parentCmd, childCmd *cobra.Command, cmdFlags map[string]*Flag)

InitCommand sets flags for a command appropriately

func InitRecursiveCommand

func InitRecursiveCommand(parentCmd, childCmd *cobra.Command, cmdFlags, recursiveFlags map[string]*Flag)

InitRecursiveCommand sets flags for a recursive command appropriately

func IsCommandOrChild added in v0.4.0

func IsCommandOrChild(command ...*cobra.Command) bool

IsCommandOrChild returns true if the provided command or one of its children was called

func MaxThreads

func MaxThreads(fThreads int) int

MaxThreads returns the maximum number of threads (goroutines) that should be spawned

func Output added in v0.2.1

func Output(i any, format string, compress bool) error

Output streams output in the specified format to stdout

func SetStandardRetrier added in v0.6.0

func SetStandardRetrier(standardDelay, maxInterval, maxElapsedTime time.Duration)

SetStandardRetrier sets the standard retrier

func Sleep added in v0.2.3

func Sleep()

Sleep sleeps for standardDelay ms plus a random jitter between 0 and 50

func StringSliceToMapSlice added in v0.2.5

func StringSliceToMapSlice(slice []string) []map[string]string

StringSliceToMapSlice converts a slice of strings to a slice of maps

Types

type Flag

type Flag struct {
	Defaults       map[string]any
	Type           string
	Description    string
	Required       []string
	AvailableFor   []string
	Recursive      []string
	ExcludeFromAll bool
}

Flag represents a flag configuration that can be easily reused for multiple commands

type Value

type Value struct {
	Value   any
	Type    string
	Index   int64
	Changed bool
	AllFlag bool
}

Value is the value representation of a flag

func (Value) GetBool

func (v Value) GetBool() bool

GetBool returns the value of the flag as a bool

func (Value) GetFloat64

func (v Value) GetFloat64() float64

GetFloat64 returns the value of the flag as a float64

func (Value) GetInt

func (v Value) GetInt() int

GetInt returns the value of the flag as an int

func (Value) GetInt64

func (v Value) GetInt64() int64

GetInt64 returns the value of the flag as an int64

func (Value) GetRune

func (v Value) GetRune() rune

GetRune returns the value of the flag as a rune

func (Value) GetString

func (v Value) GetString() string

GetString returns the value of the flag as a string

func (Value) GetStringSlice

func (v Value) GetStringSlice() []string

GetStringSlice returns the value of the flag as a []string

func (Value) GetUint64

func (v Value) GetUint64() uint64

GetUint64 returns the value of the flag as a uint64

func (*Value) IsSet

func (v *Value) IsSet() bool

IsSet returns a true or false, depending on if a flag has been set by a user

Jump to

Keyboard shortcuts

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