Skip to content

add config module#8

Merged
KARTIKrocks merged 1 commit intomainfrom
feature-config
Feb 25, 2026
Merged

add config module#8
KARTIKrocks merged 1 commit intomainfrom
feature-config

Conversation

@KARTIKrocks
Copy link
Owner

Added

  • config — New config package: load application configuration from environment variables, .env files, and JSON config files into typed Go structs
  • configLoad(dst, ...Option) populates a struct from sources in priority order (env vars > .env file > JSON file > default tags) and validates with request.ValidateStruct
  • configMustLoad(dst, ...Option) calls Load and panics on error, for use in main/init
  • config — Struct tags: env:"VAR_NAME" maps fields to env vars, default:"value" sets fallbacks, validate:"..." reuses existing request validators
  • config — Options: WithPrefix(p) for prefixed env vars (e.g., APP_PORT), WithEnvFile(path) for .env files, WithJSONFile(path) for JSON base config, WithRequired() to error on missing files
  • config — Supported types: string, bool, int/int8/16/32/64, uint variants, float32/64, time.Duration, []string, []int
  • config — Nested struct support: automatically flattened to env var names (e.g., DB.HostDB_HOST)
  • config.env file parsing: comments, blank lines, quoted values (single/double), inline comments
  • config — JSON config flattening: nested objects become underscore-separated uppercase keys
  • config — Structured error messages using *errors.Error for parse errors, validation failures, and missing files

@KARTIKrocks KARTIKrocks self-assigned this Feb 25, 2026
@KARTIKrocks KARTIKrocks merged commit fa02f1e into main Feb 25, 2026
3 checks passed
@KARTIKrocks KARTIKrocks deleted the feature-config branch March 5, 2026 05:32
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.

1 participant