configdecode

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 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 is a separate module and cannot import go-bricks/internal, so it keeps a byte-identical local copy in sync with this one.

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.

Mirrored in tools/migration/internal/commands/common.go — keep the two in sync.

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.

Mirrored in tools/migration/internal/commands/common.go (a separate module that cannot import go-bricks/internal) — keep the two in sync.

Types

This section is empty.

Jump to

Keyboard shortcuts

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