goconf is a Go tool that provides a CLI and library for generating configuration constants from YAML files and updating Go code with new constant values. Use it as a standalone CLI or import its functions directly into your tooling.
- Configuration Generation: Generate Go constants from YAML configuration files.
- Constant Updates: Replace old constant usages with new ones by comparing constant values.
- Backup & Dry-run: Optionally backup files before modifying and run in dry-run mode.
- Concurrent File Processing: Speeds up updates on large codebases.
- Cobra-based CLI: Easy-to-use command line interface.
- Clone the repository:
go install github.com/joshua-temple/goconf/cmd/goconf@latest- Build the CLI:
go build -o goconf ./cmd/goconfGenerate constants from YAML configuration files.
You can specify the target path for your YAML files, output file path, package name, and whether to create backups.
./goconf generate -t ./configs -o ./generated -p configReplace old constant names with new ones based on matching values from two Go files.
Options include dry-run and backup.
Provide the new and old constant files, and the directories containing files to update.
./goconf update -n new.go -o old.go --dirs ./pkg,./internal -d -b-d/--dry-run: Display changes without writing.-b/--backup: Create a backup file (with.bakextension) before modifying.
Import the core functions into your project without using the CLI initialization:
package main
import "github.com/joshua-temple/goconf/pkg/goconf"
var (
targetPath = "./configs"
outPath = "./generated"
packageName = "config"
backup = true
oldFile = "old.go"
newFile = "new.go"
dryRun = false
directories = []string{"./pkg", "./internal"}
)
func main() {
// ...
// Generate configuration constants:
err := goconf.GenerateConstants(targetPath, outPath, packageName, backup)
if err != nil {
// handle error
}
// Update constant usages:
err = goconf.UpdateConstants(oldFile, newFile, dryRun, backup, directories)
if err != nil {
// handle error
}
}Run unit tests with:
go test ./...Contributions are welcome! Please submit issues and pull requests on GitHub. Make sure your changes are covered by tests and follow the existing style.