Skip to content

docs: fix Handling Defaults example to use pointer field - #1

Merged
wayneashleyberry merged 3 commits into
wayneashleyberry:mainfrom
wberry-godaddy:fix/readme-defaults-example
Jul 20, 2026
Merged

wayneashleyberry merged 3 commits into
wayneashleyberry:mainfrom
wberry-godaddy:fix/readme-defaults-example

Conversation

@wberry-godaddy

Copy link
Copy Markdown
Contributor

Problem

The "Handling Defaults" section in the README recommended presetting a default on a non-pointer field (Port int) before calling strictenv.Parse. That doesn't actually work: for non-pointer fields, ParseFrom always requires the env var to be present/non-empty and returns ErrMissingValue otherwise, regardless of any value already set on the struct (see strictenv.go:86-90). The preset default was silently discarded/never reachable.

Pointer fields are the only case where a preset value is preserved when the env var is absent (strictenv.go:69-84), which is also what the passing ExampleParseFrom_defaults test already demonstrates — the README prose just didn't match it.

Fix

Updated the "Handling Defaults" example to use a pointer field, matching the actual documented/tested pointer-default behavior, and added a note clarifying that this pattern only works for optional (pointer) fields.

@wayneashleyberry wayneashleyberry self-assigned this Jul 20, 2026
@wayneashleyberry
wayneashleyberry merged commit 60832ca into wayneashleyberry:main Jul 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants