feat: support arbitrary TOML sections and wildcard schema keys - #4
Open
teal-bauer wants to merge 2 commits into
Open
feat: support arbitrary TOML sections and wildcard schema keys#4teal-bauer wants to merge 2 commits into
teal-bauer wants to merge 2 commits into
Conversation
A schema key like "dashboard.saved-locations.*.latitude" now matches any single segment in that position, e.g. ".0.latitude", ".42.latitude". Exact-match entries still take precedence over patterns during lookup. Parse splits entries into Settings (exact) and Patterns (wildcards) at load time so Has/Lookup stay O(1) for the common case.
Config is now map[string]map[string]interface{} instead of a struct with
eight named sections, so BurntSushi/toml no longer silently drops unknown
top-level sections on load. Any new [foo] section round-trips through
Redis as foo.* fields.
Replaces the hardcoded-prefix warning in service.go with a schema-based
'not in schema' warning. Fields stay persisted either way.
Converts the five indexed saved-locations schema entries from the
placeholder ".0." form to ".*." wildcards, so arbitrary indices are
recognized by the new warning logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related changes that unblock adding new top-level sections and shrink the schema's footprint for indexed data.
Arbitrary sections
BurntSushi/tomlsilently drops top-level table keys that don't match a struct field, so adding a new[profiles]or[fleet]section to/data/settings.tomlmade those settings vanish on every save cycle. Replace the hardcodedConfigstruct withmap[string]map[string]interface{}so every top-level section round-trips.As a side effect,
service.gono longer needs its hardcoded-prefix warning. Replaced withschema.Has(field)so "this field isn't declared in the schema" logs come from the schema, not a literal list in code. Fields are still persisted regardless.Wildcard schema keys
Schema keys can now contain
*segments:Matches any single segment, so
dashboard.saved-locations.42.latituderesolves the same way. Exact-match entries take precedence over patterns on collision. Parse splits entries intoSettings(exact) andPatterns(wildcard) at load time soLookupandHasstay O(1) for the common case.Converted the five existing
dashboard.saved-locations.0.*placeholder entries to.*.form, and dropped thepattern: "indexed"annotation that was standing in for the missing wildcard support.Scope
On-disk TOML format is unchanged (still quoted flat keys like
"saved-locations.0.latitude"under[dashboard]). Nested sub-tables are #3's job. Redis hashsettingsis unchanged; every field still lives there. Existing sections, keys, and defaults behave identically.Test plan
go build ./...passesgo test ./...passes[fleet],[profiles]sections serialize to TOML and flatten back to dotted Redis keysdashboard.saved-locations.0.latitudeanddashboard.saved-locations.42.latitudeboth match the.*.latitudeschema entry