utils

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: Unlicense Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultErrorProvider = ErrorProvider{SkipFrames: 2, PackageBase: "goutils"}

DefaultErrorProvider contains the default settings to use when generating errors

Functions

func As

func As[T error](inner error) T

As allows for conversion from an error to its actual type

func FromErrors

func FromErrors(errs ...error) error

FromErrors creates a new AggregateError from

Types

type AggregateError

type AggregateError []error

AggregateError is a wrapper for multiple errors

func (AggregateError) Error

func (err AggregateError) Error() string

Error generates an error string from an aggregate error

type ErrorProvider

type ErrorProvider struct {
	SkipFrames  int
	PackageBase string
}

ErrorProvider is a type that can be used when generating errors to ensure that the error is generated in the proper context

func (ErrorProvider) GenerateError

func (provider ErrorProvider) GenerateError(env string, inner error,
	message string, args ...interface{}) *GError

GenerateBackendError creates a new error from an environment variable, an inner error, a message and a list of arguments to inject into the message. Note that this function assumes that the caller generated this error. If that is not the case then a custom error provider should be used with the proper number of skip frames. See the runtime documentation for more information.

type GError

type GError struct {
	Environment string
	Package     string
	Class       string
	Function    string
	File        string
	LineNumber  int
	GeneratedAt time.Time
	Message     string
	Inner       error
}

GError contains information necessary to represent an error. We use the value GError instead of Error so, if it is embedded into another type, it will not invalidate the error interface

func NewError

func NewError(env string, inner error, message string, args ...interface{}) *GError

NewError creates a new error in the default context. See documentation of GenerateError for more information.

func (*GError) Error

func (err *GError) Error() string

Error creates an error string from the backend error

type Logger

type Logger struct {
	Environment string
	Prefix      string
	// contains filtered or unexported fields
}

Logger contains the data necessary to log status and error messages in a standard way

func NewLogger

func NewLogger(service string, environment string, opts ...LoggerOption) *Logger

NewLogger creates a new logger from the service name and environment name

func (*Logger) ChangeFrame

func (logger *Logger) ChangeFrame(skipFrames int) *Logger

ChangeFrame creates a new logger from an existing logger with a different number of frames to skip, allowing for errors to be referenced from a different part of the call stack than the default logger

func (*Logger) Discard

func (logger *Logger) Discard()

Discard is primarily used for testing. It operates by setting the output from all the loggers to a discard stream so that no logging actually appears on the screen

func (*Logger) Error

func (logger *Logger) Error(inner error, message string, args ...interface{}) *GError

Generate and log an error from the inner error and message. The resulting error will be returned for use by the caller

func (*Logger) Log

func (logger *Logger) Log(message string, args ...interface{})

Log a message to the standard output

type LoggerOption

type LoggerOption interface {
	// contains filtered or unexported methods
}

LoggerOption describes the functions necessary to modify a logger at creation

type WithErrorLog

type WithErrorLog log.Logger

WithErrorLog allows the user to set the log to which error messages will be sent

type WithErrorProvider

type WithErrorProvider ErrorProvider

WithErrorProvider allows the user to set the error provider which defines the behavior the logger should exhibit when an error message is generated

type WithInfoLog

type WithInfoLog log.Logger

WithInfoLog allows the user to set the log to which information messages will be sent

type WithPrefix

type WithPrefix string

WithPrefix allows the user to set the prefix prepended to all log messages

Jump to

Keyboard shortcuts

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