Repository navigation
Conversation
unknwon
force-pushed
the
v2-marshal-ini
branch
from
November 10, 2026 21:07
b4738fa to
6b8170d
Compare
A type with MarshalINI or UnmarshalINI formats or parses its own key value in ReflectFrom, Marshal, MapTo, StrictMapTo and Unmarshal, as a field, a pointer field or a slice element. List, ValidList, StrictList, In and Range use UnmarshalINI too. An error leaves the field unchanged, and StrictMapTo, StrictList and Marshal return it. A struct type that implements either interface maps to a key instead of a section, so types such as a host:port pair can be one value.
unknwon
force-pushed
the
v2-marshal-ini
branch
from
November 10, 2026 21:21
6b8170d to
f3f52e5
Compare
This branch has not been deployed
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.
Stacked on the v2 PR (go-ini/ini PR 425), so this merges into
v2-next.Types can now format and parse their own key values, as requested in go-ini/ini issue 353:
Where they apply
MapTo,StrictMapToandUnmarshalcallUnmarshalINIwith the value asKey.Stringreturns it. This covers a plain field, a pointer field, and each element of a slice field.List,ValidList,StrictList,InandRangecall it too, soini.List[Permission](k, ",")works.ReflectFromandMarshalcallMarshalINIfor the same kinds of field, with either a value or a pointer receiver.UnmarshalINIleaves the field unchanged inMapTo, as for any value that doesn't parse, andStrictMapToandStrictListreturn it. An error fromMarshalINIis returned byMarshalandReflectFrom.Rules
intenum readsPerm = writeinstead of failing on a non-number.host:portpair can be one value. A struct without them still maps to a section, as before.time.Timekeeps its own handling.Tests
TestMarshalerUnmarshalercovers an enum and a struct type: reading, writing and reading back, errors inMapTo,StrictMapToandMarshal, and the generic accessors. All four subtests fail without the change.FuzzStructMappingnow has enum fields of every shape. A 55-second run found nothing.