gotils

package
v0.0.0-...-948fa1a Latest Latest
Warning

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

Go to latest
Published: May 26, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//Version is a linker injected variable for a git revision info used as version info
	Version = "Unknown build"
	/*Buildstamp is a linker injected variable for a buildtime timestamp used in version info */
	Buildstamp = "unknown build timestamp."
)

Functions

func AddAdditionalExpVars

func AddAdditionalExpVars(config *Config)

AddAdditionalExpVars extends the standard expvars (see https://golang.org/pkg/expvar/ ) by some environment variables and config data.

func CheckErr

func CheckErr(err error)

CheckErr is a convenience function makes error handling dangerously simple.

func GetInspectData

func GetInspectData(config Config) string

GetInspectData offer some additional debugging information

func LogDebug

func LogDebug(format string, args ...interface{})

LogDebug works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It usses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set higher or equal to 'Debug'

func LogError

func LogError(format string, args ...interface{})

LogError works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It usses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set higher or equal to 'Error'

func LogFatal

func LogFatal(format string, args ...interface{})

LogFatal works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It usses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set hogher or equal to 'Fatal'

func LogInfo

func LogInfo(format string, args ...interface{})

LogInfo works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It usses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set higher or equal to 'Info'

func LogWarn

func LogWarn(format string, args ...interface{})

LogWarn works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It usses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set higher or equal to 'Warn'

func Maxf64

func Maxf64(v []float64) float64

Maxf64 returns the maximum of a slice of float64

func Minf64

func Minf64(v []float64) float64

Minf64 returns the minimum of a slice of float64

func ReadConfig

func ReadConfig(cfg *Config, supersedefilename ...string)

ReadConfig ...

Types

type Config

type Config struct {
	DataBase struct {
		Database string
		User     string
		Password string
	}
	Log struct {
		LogLevel       string
		ActiveLogLevel LogLevel
		LogFileName    string
		Logger         *Logger
	}
	ConfigFile string

	BuildTimeStamp time.Time
	GitVersion     string
}

Config contains the configuration data.

type Flags

type Flags struct {
	ConfigFile  string
	Database    string
	User        string
	Password    string
	LogLevel    string
	LogFileName string
}

Flags ...

type LogLevel

type LogLevel int

LogLevel sets the criticality of a logging output. It is used to filter logging messages depending on their priority. Compare to log4j.

const (
	Off LogLevel = iota
	Fatal
	Error
	Warn
	Debug
	Info
	All
)

The predefined LogLevels that are used by the logging funktions below.

func LogLevelString

func LogLevelString(s string) (LogLevel, error)

LogLevelString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func LogLevelValues

func LogLevelValues() []LogLevel

LogLevelValues returns all values of the enum

func (LogLevel) IsALogLevel

func (i LogLevel) IsALogLevel() bool

IsALogLevel returns "true" if the value is listed in the enum definition. "false" otherwise

func (LogLevel) String

func (i LogLevel) String() string

type Logger

type Logger struct {
	ActiveLoglevel LogLevel
	// contains filtered or unexported fields
}

A Logger is an onbject the offers several method to write Messages to a stream. Atually it is a wrapper aroung the 'log' package, that enhances the LogLevel functionality.

func NewLogger

func NewLogger(logfilename string, level LogLevel) *Logger

NewLogger creates a new Logger. It take a string file name as output file and a LogLevel to filter the messages that are wanted. The logger will use io.StdOut if the log filename string parameter is "STDOUT"

func NewLoggerFromFile

func NewLoggerFromFile(logfile io.Writer, level LogLevel) *Logger

NewLoggerFromFile creates a new Logger. It take a file parameter (io.Writer) output file and a LogLevel to filter the messages that are wanted. The first created logger wil be set to be the convenience logger (see the convenience functions Log...() below). Afterwards created loggers will not overwrie this. The convenience logger can be reset by using the method SetConvenienceLogger.

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...interface{})

Debug works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set higher or equal to 'Debug'

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

Error works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set higher or equal to 'Error'

func (*Logger) Fatal

func (l *Logger) Fatal(format string, args ...interface{})

Fatal works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set hogher or equal to 'Fatal'

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

Info works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set higher or equal to 'Info'

func (*Logger) SetConvenienceLogger

func (l *Logger) SetConvenienceLogger()

SetConvenienceLogger sets a logger as a singleton object. The LogInfo etc. functions use this singleton to offer logging function without an object context.

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...interface{})

Warn works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set higher or equal to 'Warn'

Jump to

Keyboard shortcuts

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