commonlib

package module
v0.0.0-...-517582e Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MIT Imports: 7 Imported by: 0

README

go-commonlib

Collection of common functions that can be used in every project

Documentation

Overview

Package for providing safety wrappers around commonly used features.

You might have at one point done this:

go myFunc()

But what happens if myFunc panics? It will terminate the program with a panic.

Commonlib provides a panic-trapping goroutine runner:

commonlib.Go(myFunc)

If `myFunc` panics, commonlib will capture the panic and log the error message.

Index

Constants

View Source
const (
	PathSeparator  = string(os.PathSeparator)
	ErrorTracepath = "errors.txt"
	ErrorTrace     = false
)
View Source
const (
	Carriage = "\n"
)

Variables

This section is empty.

Functions

func CheckError

func CheckError(inerr error, errorTrace bool, errorTracepath string) error

CheckError handle incoming errors and support additional options such as trace and logging trace to file

func Go

func Go(todo GoDoer)

Go executes a function as a goroutine, but recovers from any panics.

Normally, if a GoRoutine panics, it will stop execution on the current program, which ain't always good.

commonlib.Go handles this by trapping the panic and writing it to the default logger.

To use your own logger, use GoLog.

func GoDo

func GoDo(cxt Logger, todo GoDoer)

GoDo runs a Goroutine, traps panics, and logs panics to a lib.Logger.

Example:

cxt := any.Logger()
lib.GoDo(cxt, func(){})

func GoLog

func GoLog(logger SafelyLogger, todo GoDoer)

GoLog executes a function as a goroutine, but traps any panics.

If a panic is encountered, it is logged to the given logger.

func MTimeCheck

func MTimeCheck(name string, seconds int64) bool

MTimeCheck get modify time of file "name" and check if it more or less then "seconds" return true if modify time is less or equal then "seconds", else false

Types

type GoDoer

type GoDoer func()

GoDoer is a function that `commonlib.Go` can execute.

type Logger

type Logger interface {
	Logf(string, string, ...interface{})
}

Captures the log portion of a cookoo.Context.

type SafelyLogger

type SafelyLogger interface {
	Printf(string, ...interface{})
}

SafelyLogger is used to log messages when a failure occurs

type Timestamp

type Timestamp struct {
	time.Time
}

Time

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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