wlcontext

package
v0.0.0-...-dd4be11 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package wlcontext provides custom error types for context-related operations.

Index

Constants

View Source
const RequestDoerKey = "doer"

RequestDoerKey is the context key used to store the user making a request.

View Source
const WgKey = "wg"

WgKey is the context key used to store a WaitGroup for coordinating goroutines.

Variables

View Source
var ToZ func(c context.Context) Z

ToZ converts a context.Context to a ContextZ, panicking if the conversion fails.

Functions

func AddToWg

func AddToWg(ctx context.Context) error

AddToWg increments the WaitGroup stored in the context by one.

func NewCanceledError

func NewCanceledError(message string) error

NewCanceledError creates a new CanceledError with the given message.

func WgDone

func WgDone(ctx context.Context) error

WgDone decrements the WaitGroup stored in the context by one.

Types

type AppContexter

type AppContexter interface {
	AppCtx() Z
}

AppContexter provides access to the application's ContextZ.

type CanceledError

type CanceledError struct {
	// Message provides additional context about the error.
	Message string
}

CanceledError represents an error that occurred due to context cancellation.

func (*CanceledError) Error

func (e *CanceledError) Error() string

Error implements the error interface for CanceledError.

type DatabaseContext

type DatabaseContext interface {
	context.Context
	Database() *mongo.Database
	GetCache(cacheName string) *sturdyc.Client[any]
}

DatabaseContext provides access to MongoDB database and caching functionality.

type Doer

type Doer interface {
	Doer() string
}

Doer provides the identity of the user performing an action.

type LoggerContext

type LoggerContext interface {
	context.Context
	Log() *zerolog.Logger
}

LoggerContext provides access to a zerolog logger instance.

func Background

func Background() LoggerContext

Background returns a LoggerContext with a no-op logger for use as a background context.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, data ...websocket.WsResponseInfo)
}

Notifier sends WebSocket notifications to connected clients.

type NotifierContext

type NotifierContext interface {
	context.Context
	Notifier
}

NotifierContext provides the ability to send WebSocket notifications.

type Z

type Z interface {
	context.Context
	DatabaseContext
	LoggerContext

	WithContext(ctx context.Context) context.Context
}

Z is a context that consolidates all other context interfaces.

Jump to

Keyboard shortcuts

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