Documentation ¶
Index ¶
- func IsCancelled(ctx context.Context) bool
- func RunSafely(ctx context.Context, runnerName string, runner Runner) (err error)
- func Server(ctx context.Context, log *logan.Entry, config ServerConfig, ...)
- func UntilSuccess(ctx context.Context, log Logger, runnerName string, runner SuccessRunner, ...)
- func WithBackoff(ctx context.Context, log Logger, runnerName string, runner Runner, ...)
- type Logger
- type Runner
- type ServerConfig
- type SuccessRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsCancelled ¶
func RunSafely ¶
RunSafely executes provided runner with handling of panic. If panic happens, RunSafely returns recovered error, wrapped with additional message, which contains runnerName.
func Server ¶
func Server( ctx context.Context, log *logan.Entry, config ServerConfig, handler http.Handler, )
Server creates http.Server and makes it to ListenAndServe in a separate routine until provided context is cancelled. If Server stops with error - it will be restarted. Server method is blocking, returns after Server's Shutdown() returns.
func UntilSuccess ¶
func UntilSuccess( ctx context.Context, log Logger, runnerName string, runner SuccessRunner, minRetryPeriod, maxRetryPeriod time.Duration, )
Until success runs the runner until it returns true,nil or until provided ctx is cancelled. Passed 'log' can be nil - in this case no logging wil happen.
Types ¶
type Logger ¶
type Logger interface {
Log(level uint32, fields map[string]interface{}, err error, withStack bool, args ...interface{})
}
Logger is to avoid dependency on any particular logger (logrus and logan loggers implement this interface).
type ServerConfig ¶
type ServerConfig struct { Address string RequestWriteTimeout time.Duration ShutdownPause time.Duration // optional ShutdownTimeout time.Duration // optional }
TODO Add optional bearer token into config and check Authorization for all requests
func (ServerConfig) GetLoganFields ¶
func (s ServerConfig) GetLoganFields() map[string]interface{}
type SuccessRunner ¶
SuccessRunner describes how success-runner function must look like.
func CreateSuccessRunner ¶
func CreateSuccessRunner(r Runner) SuccessRunner
CreateSuccessRunner builds a SuccessRunner function out of the Runner function.