-
Notifications
You must be signed in to change notification settings - Fork 0
Add getter mode for runtime environment variable overrides #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📊 Code Coverage ReportCoverage by file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new "getter mode" that generates runtime-configurable code as an alternative to the existing "static mode" where values are baked at build time. The getter mode generates empty structs with getter methods that check environment variables at runtime before returning TOML defaults, making it ideal for containerized deployments and open-source projects.
Key Changes
- Added
--modeCLI flag supporting "static" (default) and "getter" modes - Implemented getter method generation with runtime environment variable checking and type-safe parsing
- Generated comprehensive documentation and examples for both modes
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| readme.md | Documents getter mode usage, examples, and comparison with static mode |
| internal/generator/struct_gen.go | Implements getter method generation with env var overrides and type conversions |
| internal/generator/generator_test.go | Adds comprehensive tests for getter mode functionality |
| internal/generator/generator.go | Adds mode support and getter-specific import generation |
| example/getter_config/config.go | Example generated code demonstrating getter mode output |
| example/gen.go | Adds getter mode to go:generate directives |
| cmd/cfgx/main.go | Adds --mode flag validation and passes mode to generator |
| cfgx.go | Updates GenerateOptions and function signatures to support mode |
| Makefile | Adds generate-example target |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| section = strings.TrimSuffix(section, "Config") | ||
| section = strings.TrimSuffix(section, "Item") |
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 611-612 are redundant since stripSuffix() already removes 'Config' and 'Item' suffixes. These duplicate trimming operations should be removed.
| section = strings.TrimSuffix(section, "Config") | |
| section = strings.TrimSuffix(section, "Item") |
Add getter mode for runtime environment variable overrides
This PR introduces a new "getter mode" generation option that provides runtime environment variable overrides as an alternative to the existing "static mode" where values are baked at build time.
Changes
--modeflag to CLI (staticorgetter)Modefield toGenerateOptionsUsage
In getter mode, the generated code returns runtime environment variable values when present, falling back to TOML defaults otherwise.