Documentation ¶
Index ¶
- func AnonymizeToken(token string, clearLen int) string
- func ConstRefBool(b bool) *bool
- func ConstRefInt32(i int32) *int32
- func ConstRefStr(s string) *string
- func EnvVarBool(varName string, defaultValue bool) bool
- func EnvVarReqStr(varName string) string
- func EnvVarSeconds(varName string, defaultValue time.Duration) time.Duration
- func EnvVarStr(varName string, defaultValue string) string
- func LoadDotEnvFile()
- func MinInt(a int, b int) int
- func RunWithPerseverance(handler func(AttemptContext), ctx GracefulContext, opts PerseverenceOpts)
- type AttemptContext
- type GracefulContext
- type GracefulRunner
- type LogTailer
- type PerseverenceOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnonymizeToken ¶
AnonymizeToken - replaces chunk of a string with '*'
func EnvVarBool ¶
EnvVarBool - retrieves value of boolean environment variable, fails if variable contains non-boolean value
func EnvVarReqStr ¶
EnvVarReqStr - retrieves value of string environment variable, fails if it is not present or empty
func EnvVarSeconds ¶
EnvVarSeconds - retrieves value of environment variable reperesenting duration in seconds, fails if variable non-parseable values
func LoadDotEnvFile ¶
func LoadDotEnvFile()
LoadDotEnvFile - Loads environment variables from .env file in the current working directory (if found)
func MinInt ¶
MinInt - returns smaller of 2 integers TODO: Go seriously doesn't have a Min function??
func RunWithPerseverance ¶
func RunWithPerseverance(handler func(AttemptContext), ctx GracefulContext, opts PerseverenceOpts)
RunWithPerseverance - runs handler and tries it again if it fails
Types ¶
type AttemptContext ¶
type AttemptContext interface { GracefulContext // GetTry - returns assigned number of tries GetTry() int }
AttemptContext - attempt context container
type GracefulContext ¶
type GracefulContext interface { // Done - blocks until cancelled Done() <-chan struct{} // RunAsChild - runs handler within child context RunAsChild(callback func(GracefulContext)) GracefulRunner // Fail - cancels run from the inside and propagates cancel to all children // Does not await the cancellation (obviously) Fail(err error) }
GracefulContext - a context carries channel factory for cancelation
type GracefulRunner ¶
type GracefulRunner interface { // Wait - blocks until finishes execution Wait() (bool, error) // Cancel - notifies handler to cancel the execution and awaits graceful return (clean up) Cancel() }
GracefulRunner - outter API for controlling gracefully run handlers
func RunWithGracefulCancel ¶
func RunWithGracefulCancel(callback func(GracefulContext)) GracefulRunner
RunWithGracefulCancel - runs callback as a go routine and returns cancel routine This is inspired by context but with the key difference that the cancel function waits until the handler finishes all the cleanup @see https://blog.golang.org/context
type LogTailer ¶
type LogTailer struct {
// contains filtered or unexported fields
}
LogTailer - implements circular buffer for tailing last n-lines
type PerseverenceOpts ¶
type PerseverenceOpts struct { // Cooldown - List of cooldown periods for failed attempts. // If execution fails more times than length of this array, last item is used. Cooldown []time.Duration // ResetThreshold - After this time failed attempts are counted as first failure ResetThreshold time.Duration // RunnerID - optional string name for the runner for debugging purposes RunnerID string }
PerseverenceOpts - options container for RunWithPerseverance