Documentation ¶
Index ¶
- Constants
- func AnyErrorIsRetryable(err error) bool
- func ApplyJitter(input int) (output int)
- func DirExists(directory string) bool
- func ExponentialBackOffDelay(n uint, config *RetryConfig) time.Duration
- func ExponentialJitterBackoffDelay(n uint, config *RetryConfig) time.Duration
- func FileExists(filename string) bool
- func FixedDelay(_ uint, config *RetryConfig) time.Duration
- func GetCommandInDirectoryOutput(ctx context.Context, dir string, command string, args ...interface{}) (string, error)
- func GetCommandOutput(ctx context.Context, command string, args ...interface{}) (string, error)
- func GetCommandWithArgsInDirectoryOutput(ctx context.Context, dir string, command string, args []string) (string, error)
- func GetCommandWithArgsOutput(ctx context.Context, command string, args []string) (string, error)
- func HandleError(err error)
- func HandleGracefulShutdown(gracefulShutdown chan os.Signal, waitGroup *sync.WaitGroup, ...)
- func InitCancellationContext(ctx context.Context) context.Context
- func InitGracefulShutdownHandling() (gracefulShutdown chan os.Signal, waitGroup *sync.WaitGroup)
- func InitLiveness()
- func InitLivenessAndReadiness()
- func InitLivenessAndReadinessWithPort(port int)
- func InitLivenessWithPort(port int)
- func InitLoggingByFormat(applicationInfo ApplicationInfo, logFormat string)
- func InitLoggingByFormatSilent(applicationInfo ApplicationInfo, logFormat string)
- func InitLoggingFromEnv(applicationInfo ApplicationInfo)
- func InitMetrics()
- func InitMetricsWithPort(port int)
- func InitReadiness()
- func InitReadinessWithPort(port int)
- func InitTracingFromEnv(app string) io.Closer
- func IntArrayContains(array []int, search int) bool
- func PathExists(path string) bool
- func Retry(retryableFunc func() error, opts ...RetryOption) error
- func RunCommand(ctx context.Context, command string, args ...interface{})
- func RunCommandExtended(ctx context.Context, command string, args ...interface{}) error
- func RunCommandExtendedCombinedStdErr(ctx context.Context, command string, args ...interface{}) error
- func RunCommandInDirectory(ctx context.Context, dir string, command string, args ...interface{})
- func RunCommandInDirectoryExtended(ctx context.Context, dir string, command string, args ...interface{}) error
- func RunCommandInDirectoryExtendedCombinedStdErr(ctx context.Context, dir string, command string, args ...interface{}) error
- func RunCommandInDirectoryWithArgs(ctx context.Context, dir string, command string, args []string)
- func RunCommandInDirectoryWithArgsExtended(ctx context.Context, dir string, command string, args []string) error
- func RunCommandInDirectoryWithArgsExtendedCombinedStdErr(ctx context.Context, dir string, command string, args []string) error
- func RunCommandWithArgs(ctx context.Context, command string, args []string)
- func RunCommandWithArgsExtended(ctx context.Context, command string, args []string) error
- func RunCommandWithArgsExtendedCombinedStdErr(ctx context.Context, command string, args []string) error
- func RunCommandWithArgsExtendedWithoutLog(ctx context.Context, command string, args []string) error
- func RunCommandWithArgsWithoutLog(ctx context.Context, command string, args []string)
- func SetLoggingLevelFromEnv()
- func StringArrayContains(array []string, search string) bool
- func ToLowerSnakeCase(in string) string
- func ToUpperSnakeCase(in string) string
- func WatchForFileChanges(filePath string, functionOnChange func(fsnotify.Event))
- type ApplicationInfo
- type DelayTypeFunc
- type IsRetryableErrorFunc
- type RetryConfig
- type RetryError
- type RetryOption
- type Semaphore
Constants ¶
const ( // LogFormatPlainText outputs logs in plain text without colorization and with timestamp; is the default if log format isn't specified LogFormatPlainText = "plaintext" // LogFormatConsole outputs logs in plain text with colorization and without timestamp LogFormatConsole = "console" // LogFormatJSON outputs logs in json including appgroup, app, appversion and other metadata LogFormatJSON = "json" // LogFormatStackdriver outputs a format similar to JSON format but with 'severity' instead of 'level' field LogFormatStackdriver = "stackdriver" // LogFormatV3 ouputs an internal format used at Travix in JSON format with nested payload and a specific set of required metadata LogFormatV3 = "v3" )
Variables ¶
This section is empty.
Functions ¶
func AnyErrorIsRetryable ¶ added in v0.0.58
AnyErrorIsRetryable is a IsRetryableErrorFunc which returns whether an error should be retried
func ApplyJitter ¶
ApplyJitter adds +-25% jitter to the input
func ExponentialBackOffDelay ¶ added in v0.0.44
func ExponentialBackOffDelay(n uint, config *RetryConfig) time.Duration
ExponentialBackOffDelay is a DelayType which increases delay between consecutive retries exponentially
func ExponentialJitterBackoffDelay ¶ added in v0.0.44
func ExponentialJitterBackoffDelay(n uint, config *RetryConfig) time.Duration
ExponentialJitterBackoffDelay returns ever increasing backoffs by a power of 2 with +/- 0-25% to prevent sychronized requests.
func FileExists ¶ added in v0.0.22
FileExists checks if a file exists
func FixedDelay ¶ added in v0.0.44
func FixedDelay(_ uint, config *RetryConfig) time.Duration
FixedDelay is a DelayType which keeps delay the same through all iterations
func GetCommandInDirectoryOutput ¶ added in v0.0.68
func GetCommandInDirectoryOutput(ctx context.Context, dir string, command string, args ...interface{}) (string, error)
GetCommandInDirectoryOutput runs a full command string and replaces placeholders with the arguments from the specified directory; it returns the output as a string and an error if command execution failed output, err := GetCommandInDirectoryOutput(ctx, "directory other than working dir", "kubectl logs -l app=%v -n %v", app, namespace)
func GetCommandOutput ¶ added in v0.0.63
GetCommandOutput runs a full command string and replaces placeholders with the arguments; it returns the output as a string and an error if command execution failed output, err := GetCommandOutput(ctx, "kubectl logs -l app=%v -n %v", app, namespace)
func GetCommandWithArgsInDirectoryOutput ¶ added in v0.0.67
func GetCommandWithArgsInDirectoryOutput(ctx context.Context, dir string, command string, args []string) (string, error)
GetCommandWithArgsInDirectoryOutput runs a single command and passes the arguments from the specified directory; it returns the output as a string and an error if command execution failed output, err := GetCommandWithArgsOutput(ctx, "directory other than working dir", "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func GetCommandWithArgsOutput ¶ added in v0.0.37
GetCommandWithArgsOutput runs a single command and passes the arguments; it returns the output as a string and an error if command execution failed output, err := GetCommandWithArgsOutput(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func HandleError ¶ added in v0.0.22
func HandleError(err error)
HandleError logs a fatal when the error is not nil
func HandleGracefulShutdown ¶
func HandleGracefulShutdown(gracefulShutdown chan os.Signal, waitGroup *sync.WaitGroup, functionsOnShutdown ...func())
HandleGracefulShutdown waits for SIGTERM to unblock gracefulShutdown and waits for the waitgroup to await pending work
func InitCancellationContext ¶ added in v0.0.36
InitCancellationContext adds cancelation to a context and on sigterm triggers the cancel function
func InitGracefulShutdownHandling ¶
InitGracefulShutdownHandling generates the channel that listens to SIGTERM and a waitgroup to use for finishing work when shutting down
func InitLiveness ¶ added in v0.0.51
func InitLiveness()
InitLiveness initializes the /liveness endpoint on port 5000
func InitLivenessAndReadiness ¶ added in v0.0.61
func InitLivenessAndReadiness()
InitLivenessAndReadiness initializes the /liveness and /readiness endpoint on port 5000
func InitLivenessAndReadinessWithPort ¶ added in v0.0.61
func InitLivenessAndReadinessWithPort(port int)
InitLivenessAndReadinessWithPort initializes the /liveness and /readiness endpoint on specified port
func InitLivenessWithPort ¶ added in v0.0.51
func InitLivenessWithPort(port int)
InitLivenessWithPort initializes the /liveness endpoint on specified port
func InitLoggingByFormat ¶ added in v0.0.31
func InitLoggingByFormat(applicationInfo ApplicationInfo, logFormat string)
InitLoggingByFormat initalializes a logger with specified format and outputs a startup message
func InitLoggingByFormatSilent ¶ added in v0.0.38
func InitLoggingByFormatSilent(applicationInfo ApplicationInfo, logFormat string)
InitLoggingByFormatSilent initializes a logger with specified format without outputting a startup message
func InitLoggingFromEnv ¶ added in v0.0.31
func InitLoggingFromEnv(applicationInfo ApplicationInfo)
InitLoggingFromEnv initalializes a logger with format specified in envvar ESTAFETTE_LOG_FORMAT and outputs a startup message
func InitMetrics ¶
func InitMetrics()
InitMetrics initializes the prometheus endpoint /metrics on port 9101
func InitMetricsWithPort ¶ added in v0.0.13
func InitMetricsWithPort(port int)
InitMetricsWithPort initializes the prometheus endpoint /metrics on specified port
func InitReadiness ¶ added in v0.0.61
func InitReadiness()
InitReadiness initializes the /readiness endpoint on port 5000
func InitReadinessWithPort ¶ added in v0.0.61
func InitReadinessWithPort(port int)
InitReadinessWithPort initializes the /readiness endpoint on specified port
func InitTracingFromEnv ¶ added in v0.0.41
InitTracingFromEnv initializes a Jaeger Tracer and returns a closer which can be defer closed in your main routine https://github.com/jaegertracing/jaeger-client-go#environment-variables
func IntArrayContains ¶ added in v0.0.57
IntArrayContains checks if an array contains a specific value
func PathExists ¶ added in v0.0.69
PathExists checks if a directory exists
func Retry ¶ added in v0.0.43
func Retry(retryableFunc func() error, opts ...RetryOption) error
Retry retries a function
func RunCommand ¶ added in v0.0.22
RunCommand runs a full command string and replaces placeholders with the arguments; it logs a fatal on error RunCommand(ctx, "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandExtended ¶ added in v0.0.22
RunCommandExtended runs a full command string and replaces placeholders with the arguments; it returns an error if command execution failed err := RunCommandExtended(ctx, "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandExtendedCombinedStdErr ¶ added in v0.0.80
func RunCommandExtendedCombinedStdErr(ctx context.Context, command string, args ...interface{}) error
RunCommandExtended runs a full command string and replaces placeholders with the arguments; it returns an error combined stderr if command execution failed err := RunCommandExtended(ctx, "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandInDirectory ¶ added in v0.0.67
RunCommandInDirectory runs a full command string and replaces placeholders with the arguments from the specified directory; it logs a fatal on error RunCommandInDirectory(ctx, "directory other than working dir", "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandInDirectoryExtended ¶ added in v0.0.67
func RunCommandInDirectoryExtended(ctx context.Context, dir string, command string, args ...interface{}) error
RunCommandInDirectoryExtended runs a full command string and replaces placeholders with the arguments from the specified directory; it returns an error if command execution failed err := RunCommandInDirectoryExtended(ctx, "directory other than working dir", "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandInDirectoryExtendedCombinedStdErr ¶ added in v0.0.79
func RunCommandInDirectoryExtendedCombinedStdErr(ctx context.Context, dir string, command string, args ...interface{}) error
RunCommandInDirectoryExtended runs a full command string and replaces placeholders with the arguments from the specified directory; it returns an error combined stderr if command execution failed err := RunCommandInDirectoryExtended(ctx, "directory other than working dir", "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandInDirectoryWithArgs ¶ added in v0.0.67
RunCommandInDirectoryWithArgs runs a single command and passes the arguments from the specified directory; it logs a fatal on error RunCommandInDirectoryWithArgs(ctx, "directory other than working dir", "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandInDirectoryWithArgsExtended ¶ added in v0.0.67
func RunCommandInDirectoryWithArgsExtended(ctx context.Context, dir string, command string, args []string) error
RunCommandInDirectoryWithArgsExtended runs a single command and passes the arguments from the specified directory; it returns an error if command execution failed err := RunCommandInDirectoryWithArgsExtended(ctx, "directory other than working dir", "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandInDirectoryWithArgsExtendedCombinedStdErr ¶ added in v0.0.79
func RunCommandInDirectoryWithArgsExtendedCombinedStdErr(ctx context.Context, dir string, command string, args []string) error
RunCommandInDirectoryWithArgsExtended runs a single command and passes the arguments from the specified directory; it returns an error combined stderr if command execution failed err := RunCommandInDirectoryWithArgsExtended(ctx, "directory other than working dir", "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgs ¶ added in v0.0.22
RunCommandWithArgs runs a single command and passes the arguments; it logs a fatal on error RunCommandWithArgs(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgsExtended ¶ added in v0.0.22
RunCommandWithArgsExtended runs a single command and passes the arguments; it returns an error if command execution failed err := RunCommandWithArgsExtended(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgsExtendedCombinedStdErr ¶ added in v0.0.80
func RunCommandWithArgsExtendedCombinedStdErr(ctx context.Context, command string, args []string) error
RunCommandWithArgsExtendedCombinedStdErr runs a single command and passes the arguments; it returns an error combined stderr if command execution failed err := RunCommandWithArgsExtended(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgsExtendedWithoutLog ¶ added in v0.0.82
RunCommandWithArgsExtendedWithoutLog runs a single command and passes the arguments; it returns an error if command execution failed without any log output err := RunCommandWithArgsExtendedWithoutLog(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgsWithoutLog ¶ added in v0.0.82
RunCommandWithArgsWithoutLog runs a single command and passes the arguments; it logs a fatal on error without any log output RunCommandWithArgsWithoutLog(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func SetLoggingLevelFromEnv ¶ added in v0.0.49
func SetLoggingLevelFromEnv()
SetLoggingLevelFromEnv sets the logging level from which log messages and higher are outputted via envvar ESTAFETTE_LOG_LEVEL
func StringArrayContains ¶ added in v0.0.42
StringArrayContains checks if an array contains a specific value
func ToLowerSnakeCase ¶ added in v0.0.45
ToLowerSnakeCase turns any input string into an lower snake cased string
func ToUpperSnakeCase ¶ added in v0.0.45
ToUpperSnakeCase turns any input string into an upper snake cased string
func WatchForFileChanges ¶
WatchForFileChanges waits for a change to the provided file path and then executes the function
Types ¶
type ApplicationInfo ¶ added in v0.0.39
type ApplicationInfo struct { AppGroup string App string Version string Branch string Revision string BuildDate string }
ApplicationInfo contains basic information about an application
func NewApplicationInfo ¶ added in v0.0.40
func NewApplicationInfo(appgroup, app, version, branch, revision, buildDate string) ApplicationInfo
NewApplicationInfo returns an ApplicationInfo object
func (*ApplicationInfo) GoVersion ¶ added in v0.0.39
func (ai *ApplicationInfo) GoVersion() string
GoVersion returns the golang version used to build an application
func (*ApplicationInfo) OperatingSystem ¶ added in v0.0.39
func (ai *ApplicationInfo) OperatingSystem() string
OperatingSystem returns the current operating system
type DelayTypeFunc ¶ added in v0.0.43
type DelayTypeFunc func(n uint, config *RetryConfig) time.Duration
DelayTypeFunc allows to override the DelayType
type IsRetryableErrorFunc ¶ added in v0.0.58
IsRetryableErrorFunc allows to apply custom logic to whether an error is retryable
type RetryConfig ¶ added in v0.0.43
type RetryConfig struct { Attempts uint DelayMillisecond int DelayType DelayTypeFunc LastErrorOnly bool IsRetryableError IsRetryableErrorFunc }
RetryConfig is used to configure the Retry function
type RetryError ¶ added in v0.0.43
type RetryError []error
RetryError contains all errors for each failed attempt
func (RetryError) Error ¶ added in v0.0.43
func (e RetryError) Error() string
Error method return string representation of Error It is an implementation of error interface
type RetryOption ¶ added in v0.0.43
type RetryOption func(*RetryConfig)
RetryOption allows to override config
func AnyError ¶ added in v0.0.58
func AnyError() RetryOption
AnyError is sets AnyErrorIsRetryable as IsRetryableError
func Attempts ¶ added in v0.0.43
func Attempts(attempts uint) RetryOption
Attempts set count of retry default is 3
func DelayMillisecond ¶ added in v0.0.43
func DelayMillisecond(delayMilliSeconds int) RetryOption
DelayMillisecond sets delay between retries default is 100ms
func ExponentialBackOff ¶ added in v0.0.58
func ExponentialBackOff() RetryOption
ExponentialBackOff sets ExponentialBackOffDelay as DelayType
func ExponentialJitterBackoff ¶ added in v0.0.43
func ExponentialJitterBackoff() RetryOption
ExponentialJitterBackoff sets ExponentialJitterBackoffDelay as DelayType
func LastErrorOnly ¶ added in v0.0.59
func LastErrorOnly(value bool) RetryOption
LastErrorOnly sets LastErrorOnly config value
type Semaphore ¶ added in v0.0.70
type Semaphore interface { // Acquire tries to get a lock and blocks until it does Acquire() // GetAcquireChannel returns the inner channel to be used to acquire a lock within a select statement GetAcquireChannel() chan struct{} // Release releases a lock Release() // Wait until all locks are released Wait() }