common

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: 0BSD Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Log = &logrus.Logger{
	Out:       os.Stdout,
	Formatter: new(logrus.TextFormatter),
	Hooks:     make(logrus.LevelHooks),
	Level:     logrus.InfoLevel,
}

Info:

Log.Info("Info")

Debug:

Log.Debug("Debug")

Error:

Log.Error("Error")

Warn:

Log.Warn("Warn")

Functions

func CheckErr

func CheckErr(err error, trace string) bool

This function checks for an error.

If the error isn't nil it return true and print error otherwise false.

err := errors.New("Test Error")
if common.CheckErr(err, "example error") {
	return
}

fmt.Println("No error was found!")

func Retry added in v0.4.0

func Retry(attempts int, sleep time.Duration, f func() error) (err error)

If there is an error in the performed function, it will be restarted, this process will be repeated the given number of times

e.g.

err := Retry(3, 5*time.Second, connectToDB)

if err != nil {
	Log.Error(err)
}

func Uptime

func Uptime(start time.Time) string

Return uptime of program e.g. "10m 4s"

Types

This section is empty.

Jump to

Keyboard shortcuts

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