contexts

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapHandlerContext

func WrapHandlerContext(handlerCtx context.Context, realCtx *Context) context.Context

These are a workaround to provide the serve context to handler functions. Wrap the handler context with the real context, and return the real context as the stdlib context type.

Types

type Context

type Context struct {
	context.Context
	Log       *LoggerContext
	Stopwatch *StopwatchContext
	// contains filtered or unexported fields
}

This should only contain fields that are realistically needed collectively whenever one is needed, while processing a DR command. This reduces the number of arguments that need to be passed around in the codebase. Doing so improves readability, at the cost of more "global" type values. However, given that nearly everything will need these values anyway, there isn't much downside in grouping them together.

func NewContext

func NewContext(ctx context.Context) *Context

func UnwrapHandlerContext

func UnwrapHandlerContext(ctx context.Context) *Context

Unwrap the real context from the stdlib context type. If the context was not properly attached, return a new context with a message about the issue.

func (*Context) Child

func (c *Context) Child() *Context

func (*Context) IsChildOf

func (c *Context) IsChildOf(maybeParentCtx *Context) bool

func (*Context) WithLogger

func (c *Context) WithLogger(logger *LoggerContext) *Context

func (*Context) WithTimeout

func (c *Context) WithTimeout(timeout time.Duration) (*Context, context.CancelFunc)

Returns a new context with the given timeout. If the timeout is 0, the new context will be cancellable, but will not have a timeout.

type DeferredKeyval

type DeferredKeyval struct {
	Key   string
	Value func() interface{}
}

func NewDeferredKeyval

func NewDeferredKeyval(key string, value func() interface{}) *DeferredKeyval

func (*DeferredKeyval) Keyval

func (dk *DeferredKeyval) Keyval() []interface{}

type DeferredKeyvalInterface

type DeferredKeyvalInterface interface {
	Keyval() []interface{}
}

func ErrorKeyvals

func ErrorKeyvals(err *error) DeferredKeyvalInterface

Creates a common keyval for a future error. If the error is nil, the keyval will be be omitted entirely.

type LoggerContext

type LoggerContext struct {
	*log.Logger
	// contains filtered or unexported fields
}

func NewLoggerContext

func NewLoggerContext(logger *log.Logger) *LoggerContext

func (*LoggerContext) Debug

func (lc *LoggerContext) Debug(msg interface{}, keyvals ...interface{})

func (*LoggerContext) Debugf

func (lc *LoggerContext) Debugf(format string, args ...interface{})

func (*LoggerContext) Error

func (lc *LoggerContext) Error(msg interface{}, keyvals ...interface{})

func (*LoggerContext) Errorf

func (lc *LoggerContext) Errorf(format string, args ...interface{})

func (*LoggerContext) Fatal

func (lc *LoggerContext) Fatal(msg interface{}, keyvals ...interface{})

func (*LoggerContext) Fatalf

func (lc *LoggerContext) Fatalf(format string, args ...interface{})

func (*LoggerContext) GetPrefix

func (lc *LoggerContext) GetPrefix() string

func (*LoggerContext) Info

func (lc *LoggerContext) Info(msg interface{}, keyvals ...interface{})

func (*LoggerContext) Infof

func (lc *LoggerContext) Infof(format string, args ...interface{})

func (*LoggerContext) Log

func (lc *LoggerContext) Log(level log.Level, msg interface{}, keyvals ...interface{})

func (*LoggerContext) Logf

func (lc *LoggerContext) Logf(level log.Level, format string, args ...interface{})

func (*LoggerContext) Print

func (lc *LoggerContext) Print(msg interface{}, keyvals ...interface{})

func (*LoggerContext) Printf

func (lc *LoggerContext) Printf(format string, args ...interface{})

func (*LoggerContext) SetPrefix

func (lc *LoggerContext) SetPrefix(prefix string)

func (*LoggerContext) Step

func (lc *LoggerContext) Step() *LoggerContext

Creates a new logger instance with the same logger as the current logger, but with a new prefix that includes the step count. Successive calls to Step will increment the step count.

func (*LoggerContext) Warn

func (lc *LoggerContext) Warn(msg interface{}, keyvals ...interface{})

func (*LoggerContext) Warnf

func (lc *LoggerContext) Warnf(format string, args ...interface{})

func (*LoggerContext) With

func (lc *LoggerContext) With(keyvals ...interface{}) *LoggerContext

Simple wrapper for the underlying logger `With` that returns the logger context.

type StopwatchContext

type StopwatchContext struct {
	StartTime time.Time
}

func NewStopwatchContext

func NewStopwatchContext() *StopwatchContext

func (*StopwatchContext) Elapsed

func (sc *StopwatchContext) Elapsed() time.Duration

func (*StopwatchContext) Keyval

func (sc *StopwatchContext) Keyval() *DeferredKeyval

Jump to

Keyboard shortcuts

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