config/: multi-format support (TOML/YAML/JSON) + API cleanup #23
Labels
No labels
harness
proj-core-console
proj-core-demo
proj-core-edit
proj-core-init
proj-core-lib
proj-core-login
proj-core-res
proj-core-sh
proj-core-theme
proj-docs
proj-extra-calc
proj-extra-code
proj-extra-playbook
proj-extra-sheets
proj-harness
proj-os
residual
tier-0-trivial
tier-1-easy
tier-2-medium
tier-3-hard
tier-4-major
tier-5-epic
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
residual/.agent#23
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Multi-format support + App API cleanup
Extend the standalone
config/library to support TOML, YAML, and JSON config files. Clean up theAppAPI so developers don't need to configure directories.Changes
1. App struct cleanup (
core/app.go)SystemDir/UserDir→systemDir/userDir(computed byNew())Ext stringfield (default"toml") — developer sets this to choose formatSystemPath()/UserPath()lose theirextparameter, usea.ExtNewWithOptions()stays but documented as testing-onlyfilepath.Joinhandles empty group correctly:filepath.Join("/etc", "", "myapp.toml")→/etc/myapp.toml2. Rename
ReadFile→Custom(core/load.go,stubs.go)Custom[T](path string) (T, error)— explicit path + auto-detect format from extensionDefaults → System → User → Custom → EnvLoadfunction andOptionstype (dead API, no callers)3. Add YAML and JSON codecs (
core/codec.go)gopkg.in/yaml.v3for YAMLencoding/json(stdlib) for JSON.yaml,.yml,.jsonin handler mapdecode,encode,decodeRawfunctions4. Update callers (
core/load.go,core/write.go)System/Usercalla.SystemPath()/a.UserPath()(no hardcoded"toml")WriteUser/WriteSystemcalla.UserPath()/a.SystemPath()5. Update docs and tests
Extfield, multi-format,Customin cascade chainReadFile→Custom, add YAML/JSON round-tripsNew usage
Verification
Implementation complete
All changes shipped. Summary:
App API cleanup
SystemDir/UserDirunexported — computed byNew()from/etcand~/.configExt stringfield (default"toml") — developer sets formatSystemPath()/UserPath()usea.Ext, no parameter neededNewWithOptions()kept for testing onlyMulti-format support
gopkg.in/yaml.v3) and JSON (encoding/json) codecs.yaml,.yml,.jsonin handler mapSystem/User/WriteUser/WriteSystemuseapp.ExtCustom/WriteFileauto-detect from file extensionAPI rename
ReadFile→Custom(cascade chain: Defaults → System → User → Custom → Env)Loadfunction andOptionstypeenvNameForPathfunctionTests
.yamland.jsonextensionsFiles changed
core/app.go— unexported dirs, added Ext, updated path methodscore/codec.go— added YAML/JSON handlerscore/load.go— renamed ReadFile→Custom, removed deprecated APIcore/write.go— use app.Ext for pathsstubs.go— updated re-exportsconfig.go— updated package doccmd/res-validate-config/main.go— ReadFile→Customgo.mod/go.sum— added gopkg.in/yaml.v3load_test.go— updated + new YAML/JSON testswrite_test.go— updated + new YAML/JSON testsREADME.md— rewritten with multi-format docsVerification
go build,go test(48/48 pass),go vetall clean.