19 lines
884 B
Go
19 lines
884 B
Go
// Package assert provides compile-time-removable invariant checks.
|
|
//
|
|
// Use assert to document programmer contracts — preconditions, postconditions,
|
|
// and internal invariants that should be logically impossible to violate if the
|
|
// code is correct. A triggered assertion is always a bug, never a user error.
|
|
//
|
|
// Assertions are enabled by default (dev/debug builds). Disable them in
|
|
// production builds by passing -tags assert_disable to the Go toolchain:
|
|
//
|
|
// go build -tags assert_disable ./...
|
|
//
|
|
// In a disabled build both [That] and [Thatf] are compiled out entirely — no
|
|
// condition is evaluated and no allocation occurs.
|
|
//
|
|
// Contrast with [gitea.djmil.dev/go/template/pkg/result], which handles runtime
|
|
// correctness (I/O, parsing, external inputs). Use result for things that can
|
|
// legitimately fail; use assert for things that must never fail.
|
|
package assert
|