Repository navigation
feat(read): support array index path in Get, eg. parent.child[1] - #231
Merged
Merged
Conversation
inhere
added a commit
that referenced
this pull request
Oct 29, 2026
GetValue and Exists each carried the same hand-written path walk next to the bracket-index expansion added in #231, while gookit/goutil resolves the whole path now (bracket indexes, literal keys matched first, typed maps since v0.8.6). - GetValue and Exists delegate to maputil.GetByPathKeys, so the local expandKeyIndexes/expandSegIndex helpers and both walks are gone. - recordGetPathError keeps the old error report: a path that runs into a value which cannot have sub-keys still records "cannot get value of the key 'x'", while a missing key stays silent. - a non-numeric index into a slice (eg. "arr1.notExist") is a plain not-found now instead of a recorded strconv error. - bump github.com/gookit/goutil to v0.8.6, which resolves map[string]int and other typed maps that Set() may store. Tests: the existing suite covers the array index paths, the map[string]int values, Exists parity and the top-level literal key; no assertion changed.
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.
Closes the remaining gap of #96: setting array elements by path with an
index (
Set("parent.child[0]", ...)) already works today (viamaputil.SetByKeys,verified against goutil v0.8.3), but reading them back with the same syntax
did not -
Get("parent.child[1]")returned nothing, since only thedot-index form (
parent.child.1) was understood.GetValueandExistsnow expand trailing[N]markers in path segments:Details:
brackets keep working;
child[x]) are treated as literalkeys, as before;
matrix[0][1]);parent.child.1) is unchanged.Tests cover set/get round-trip, nested paths, out-of-range/negative indexes,
non-numeric indexes and the
Existsparity.Closes #96