Documentation ¶
Overview ¶
Package gsmhelpers contains helper functions to GSM
Index ¶
- Variables
- func ActionRetry(errKey string, c func() error) (bool, error)
- func Contains[T comparable](value T, slice []T) bool
- func EnsurePrefix(s, p string) string
- func FlagToMap(value string) (m map[string]string)
- func FlagsToMap(flags *pflag.FlagSet) (m map[string]*Value)
- func FormatErrorKey(s ...string) string
- func GetAllFlags(flags map[string]*Flag) map[string]*Flag
- func GetBatchMaps(cmd *cobra.Command, cmdFlags map[string]*Flag) (<-chan map[string]*Value, error)
- func GetCSVContent(path string, delimiter rune, skipHeader bool) ([][]string, error)
- func GetFileContentAsString(path string) (string, error)
- func GetJSONEncoder(indent bool) *json.Encoder
- func GetObjectRetry(errKey string, c func() (any, error)) (any, error)
- func InitBatchCommand(parentCmd, childCmd *cobra.Command, ...)
- func InitCommand(parentCmd, childCmd *cobra.Command, cmdFlags map[string]*Flag)
- func InitRecursiveCommand(parentCmd, childCmd *cobra.Command, cmdFlags, recursiveFlags map[string]*Flag)
- func IsCommandOrChild(command ...*cobra.Command) bool
- func MaxThreads(fThreads int) int
- func Output(i any, format string, compress bool) error
- func SetStandardRetrier(standardDelay, maxInterval, maxElapsedTime time.Duration)
- func Sleep()
- func StringSliceToMapSlice(slice []string) []map[string]string
- type Flag
- type Value
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 FlagToMap ¶
FlagToMap first splits a string by ";" to get the attributes, then each attribute is split by "=" to get the key / value pair
func FlagsToMap ¶
FlagsToMap converts all flags to a map
func FormatErrorKey ¶
FormatErrorKey formats an error key. Error keys are used on error messages to make it easier to debug where an error occurred
func GetAllFlags ¶
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 ¶
GetBatchMaps returns a channel containing maps to be used for batch requests to the Google API
func GetCSVContent ¶
GetCSVContent gets the content of a CSV file as [][]string
func GetFileContentAsString ¶
GetFileContentAsString returns the content of a file as a string
func GetJSONEncoder ¶ added in v0.2.1
GetJSONEncoder returns a new json encoder
func GetObjectRetry ¶
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 ¶
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
IsCommandOrChild returns true if the provided command or one of its children was called
func MaxThreads ¶
MaxThreads returns the maximum number of threads (goroutines) that should be spawned
func SetStandardRetrier ¶ added in v0.6.0
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
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 ¶
Value is the value representation of a flag
func (Value) GetFloat64 ¶
GetFloat64 returns the value of the flag as a float64
func (Value) GetStringSlice ¶
GetStringSlice returns the value of the flag as a []string