nilguard

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nilguard gives a usable value for an argument that a caller may leave nil: a context or a logger. The entry points of the library tolerate a nil there rather than panic, so that none of the components behind them needs to check.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextOrBackground

func ContextOrBackground(ctx context.Context) context.Context

ContextOrBackground returns ctx, or the background context when ctx is nil. Passing a nil context is a mistake of the caller (staticcheck SA1012), the entry points of the library tolerate it rather than panic.

func LoggerOrDiscard

func LoggerOrDiscard(logger *slog.Logger) *slog.Logger

LoggerOrDiscard returns logger, or a logger that discards everything when logger is nil: the entry points that take a logger give their components a usable one, so that none of them needs to check for nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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