configdecode

package
v0.72.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package configdecode holds mapstructure decode hooks shared by the go-bricks config and migration packages, so the decode guards have a single source of truth inside the module. The tools/migration CLI keeps no copy: it decodes its config file through config.LoadFromMap, so it runs these hooks at the go-bricks version it pins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyStringToScalarGuardHookFunc added in v0.60.0

func EmptyStringToScalarGuardHookFunc() mapstructure.DecodeHookFunc

EmptyStringToScalarGuardHookFunc rejects an empty (or whitespace-only) string bound to a numeric or bool field. WeaklyTypedInput would otherwise coerce it to that target's zero value — 0 for a numeric, false for a bool — so a set-but-empty environment variable (FOO=) or an empty YAML string decodes as a legal zero and boots a config nobody wrote: the tri-states in ADR-065 and ADR-046 are defeated exactly this way, and database.pool.keepalive.enabled flips from its default true to false. Pointer targets are guarded too: the zero arrives as a non-nil *0 / *false, which normalization reads as "operator set it".

time.Duration is exempt: StringToTimeDurationHookFunc owns that target and already fails loudly on an empty string. Every other target is untouched — an empty string is a legal string, and the database-identity subset is ADR-051's to judge.

func NumericToDurationGuardHookFunc

func NumericToDurationGuardHookFunc() mapstructure.DecodeHookFunc

NumericToDurationGuardHookFunc rejects a bare numeric bound to a time.Duration field: WeaklyTypedInput would otherwise coerce it to that many raw nanoseconds (300 -> 300ns), booting a broken config. Edge cases: an explicit zero (int/uint/float, incl. -0.0) is the framework-wide "unset -> use default" idiom and passes; a bool is never a duration and is always rejected; a source that is already time.Duration (e.g. a typed default) passes. Guards exact time.Duration only, matching StringToTimeDurationHookFunc's scope.

Types

This section is empty.

Jump to

Keyboard shortcuts

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