util

package module
v0.0.0-...-878f23c Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: MIT Imports: 8 Imported by: 3

README

NOTE: This is deprecated in favor of Appkit.

go-util

Some generic code for my personal projects. A shared repository to reduce copy-pasting.

MIT-License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var E = ErrorHandler{
	Out:             os.Stderr,
	PrintStackTrace: true,
}

The default error handler

Functions

func Fault

func Fault(err error, message string, arg ...string)

Fault checks if given err is != nil and if it is runs os.Exit(1). This should be used as a top level handling of errors in the main()

func VersionString

func VersionString(opts Options) string

VersionString returns a version string that should be printed with the -v or the --version flag. It gets the components from the following keys from the options: program-name program-version program-timestamp

Types

type ErrorHandler

type ErrorHandler struct {
	Out             io.Writer
	PrintStackTrace bool
}

func (*ErrorHandler) Annotate

func (e *ErrorHandler) Annotate(err error, a ...interface{}) error

Annotate increases context information to the error

func (*ErrorHandler) New

func (e *ErrorHandler) New(format string, a ...interface{}) error

New creates a new error variable

func (*ErrorHandler) Panic

func (e *ErrorHandler) Panic(err error, a ...interface{})

func (*ErrorHandler) Print

func (e *ErrorHandler) Print(err error, a ...interface{})

Print writes the error message to predefined io.Writer

type ErrorList

type ErrorList struct {
	Message string
	// contains filtered or unexported fields
}

ErrorList is a list of errors that can be printed in a single go

func NewErrorList

func NewErrorList(message string) (ret *ErrorList)

NewErrorList returns an initialized ErrorList

func (*ErrorList) Append

func (e *ErrorList) Append(err error)

Append adds a new error to the list

func (*ErrorList) Error

func (e *ErrorList) Error() string

Error returns the error string generated from the list

func (*ErrorList) IsEmpty

func (e *ErrorList) IsEmpty() bool

IsEmpty returns true if the error list is empty

type Options

type Options interface {
	Set(key string, value string)
	Get(key string, fallback string) string
	IsSet(key string) bool
}

Options is an interface to get and set string-like options for components

func GetOptions

func GetOptions() Options

GetOptions gets the static options structure

func NewOptions

func NewOptions() Options

NewOptions returns a new Options structure

type Profiler

type Profiler struct {
	// contains filtered or unexported fields
}

Profiler is a structure to simplify generating CPU and memory profile files from a run of a program.

func SetupProfiler

func SetupProfiler(opts Options) (*Profiler, error)

SetupProfiler sets up an empty profiler with Options. The options should contain keys "profile-cpu-file" which is the file name for the CPU profile. Also the memory profile will be written to value of key "profile-mem-file".

func (*Profiler) Close

func (p *Profiler) Close() error

Close finishes the creation of the profile. Should be defer'd after running Setup.

Jump to

Keyboard shortcuts

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