| Age | Commit message (Collapse) | Author |
|
With help of spdxconv tool [1], we able to bulk update all files license
and copyright format to comply with SPDX formats.
[1] https://kilabit.info/project/spdxconv/
|
|
HTTP request now implicitly create request with context.
Any false positive related to not closing HTTP response body has been
annotated with "nolint:bodyclose".
In the example code, use consistent "// Output:" comment format, by
prefixing with single space.
Any comment on code now also prefixing with single space.
An error returned without variables now use [errors.New] instead of
[fmt.Errorf].
Any error returned using [fmt.Errorf] now wrapped using "%w" instead of
"%s".
Also, replace error checking using [errors.Is] or [errors.As], instead
of using equal/not-equal operator.
Any statement like "x = x OP y" now replaced with "x OP= y".
Also, swap statement is simplified using "x, y = y, x".
Any switch statement with single case now replaced with if-condition.
Any call to defer on function or program that call [os.Exit], now
replaced by calling the deferred function directly.
Any if-else condition now replaced with switch statement, if possible.
|
|
The Keys method return sorted list of all section, subsection, and
variables as string where each of them separated by ":", for example
"section:sub:var".
|
|
Previously, appending a new variable into section always create an empty
line before after the variable.
For example, given the following section,
[a]
k = v
[c]
append "k2=v2" to section "a" will result
[a]
k = v
k2=v
[c]
This changes fix this by appending variable only after non-empty lines,
which result to
[a]
k = v
k2= v
[c]
While at it, add empty space before variable value.
|
|
|
|
The realignment reduce the cost of the following struct,
* U in ExampleMarshal_map: from 32 to 24 bytes (-8)
* U in ExampleUnmarshal_map: from 32 to 24 bytes (-8)
|
|
While at it, clean up some codes to make it more readable and debug-able.
|
|
Previously, if INI file contains multi line variables, for example
key = a \
b
The Get and saved value is "a \tb", where it should be "a b" for Get and
"a \\\n\t\b" again when saved.
This changes require refactoring how the variable's value is parsed and
stored.
A variable value is parsed and stored from character after "=" until new
line or comment as raw value, and the real value is derived by trimming
white spaces, handle escaped character and double quotes.
|
|
While at it, split the example for marshaling and unmarshaling
struct into separate examples.
|
|
For a field F with type map[K]S `ini:"sec"`, where K is string and S is
a struct or pointer to struct element, marshaling the field F will
result in the following ini format,
[sec "K"]
<S.Field.Tag> = <S.Field.Value>
Each field in struct S unmarshaled normally as "key = value".
This rule is also applied when unmarshalling from ini text into map[K]V.
This implementation allow multiple section with dynamic subsections as
key.
|
|
Changes,
* reader: from 184 to 168 bytes (-16 bytes)
* Section: from 104 to 88 bytes (-16 bytes)
* structField: from 120 to 112 bytes (-8 bytes)
* variable: from 120 to 104 bytes (-16 bytes)
|
|
Reformat and update the documentation to be more readable and the
examples to be self-explainable.
|
|
Give the following field struct with tag,
V *T `ini:"sec:sub"
If the V is not nil, it will marshal it into,
[sec "sub"]
<field name or tag> = <field value>
|
|
Previously, we use the passed struct as reference for unmarshalling
the ini text into struct. This model on unmarshaling does not works well
if we want to unmarshal to slice of struct.
This commit changes the way the unmarshal works by iterating over
section and variables from parsed ini text file and do a lookup on the
passed struct to find field that match the section, subsection and key.
With this model we can unmarshal a section-subsction into struct
or slice of struct.
|
|
Given a struct with exported field is slice of struct and tagged with
section and sub-section, the exported field will be marshalled as,
[section "sub"]
field = value
|
|
In this way, the example code for Marshal and Unmarshal display how
the struct defined and tagged.
|
|
In Git specification, an empty variable is equal to boolean true.
This cause inconsistency between empty string and boolean true.
This changes make the empty value become an empty string instead of
boolean true.
|
|
|
|
|
|
Previously, Gets return uniq, non-duplicate values. This changes make
the Gets return the values as is.
|
|
|
|
|
|
|
|
The Unmarshal function parse the INI stream as slice of byte and store
its value into struct of `v`.
All the property and specification of field's tag follow the Marshal
function.
|
|
Marshal encode the struct of v into stream of ini formatted string.
To encode a struct, an exported fields must have tagged with "ini" key;
untagged field will not be exported.
Each exported field in the struct must have at least one tag: a section
where the field's name (the key) and field's value will be saved.
An optional subsection can be defined by adding a string separated by
colon ":" after section's name.
An optional key's name also can be defined by adding string after
subsection name.
If key's name is not defined it would be default to lowercase string of
field's name.
An array or slice will be encoded as multiple keys.
One exception to above rule is map type.
A map's key will override the key defined in tag.
|
|
For readibility, each section should start with an empty line.
|
|
Previous behaviour of Set() method will return false if the section
or subsection of key to be set not found on database.
This commit change the behaviour of Set(). If no section or subsection
found on database, the new section with key-value will be created.
If no key found, the new key-value will be added to the specific section.
|
|
|
|
Given a section name and/or subsection name, Vars() method will return
all variables as map of key and value.
If there is a duplicate in key's name, only the last key value that will
be store on map value.
This method is a shortcut that can be used in templating.
|
|
If section name is not empty, only the keys will be listed in the map.
|
|
The following methods are added to support templating using this package,
* Subs(): a method that return all non-empty subsections
* Val(): a method that return the last variable's value using key's path
as combination of section-name ":" sub-section-name ":" key.
* Vals(): a method that return all variable values as slice of string
This changes cause the section type to be exported back, again.
|
|
The Add() method will add new key and value to the last item in section
and/or subsection.
The Set() method set the last variable's value in section-subsection that
match with the key.
The Unset() method will remove the last variable's in section and/or
subsection that match with the key.
|
|
This is the first part to refactoring ini package to provide a clean
and simple API.
|
|
Basically, Rebase merge each sections in other INI object on top of
current INI object.
|
|
Pruning the INI variables means removing the empty lines, the comments,
and merge section and subsection that have the same name into one
group.
|
|
|
|
AsMap return the INI contents as mapping of
(section "." subsection "." var) as key
and the variable's value as slice of string.
For example, given the following INI file,
[section1]
key = value
[section2 "sub"]
key2 = value2
key2 = value3
it will be mapped as,
map["section1..key"] = []string{"value"}
map["section2.sub.key2"] = []string{"value2", "value3"}
|