aboutsummaryrefslogtreecommitdiff
path: root/lib/ini/ini.go
AgeCommit message (Collapse)Author
10 daysall: apply go fixShulhan
2025-01-23all: use for-range with numericShulhan
Go 1.22 now support for-range on numeric value.
2025-01-23all: replace "interface{}" with "any"Shulhan
2024-08-04lib/ini: mention that marshaling []byte does not supportedShulhan
Due to "byte" is considered as "uint8" during reflection, we cannot tell whether the value is slice of byte of slice of number with type uint8.
2024-03-05all: comply with linter recommendations #2Shulhan
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.
2024-03-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2024-01-14lib/ini: add method KeysShulhan
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".
2024-01-14lib/ini: use method IsExported in marshalStructShulhan
Since Go 1.17, the [reflect.StructField] add method IsExported which give clear indication that the field is exported rather than checking not-empty PkgPath.
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-11-17lib/ini: create the file if its not exist on OpenShulhan
2023-09-14all: fix variable shadowing as reported by shadow toolShulhan
The shadow tool [1] report a variable where its name is declared twice or more, in different scope. [1] https://pkg.go.dev/golang.org/x/tools@v0.13.0/go/analysis/passes/shadow
2023-09-11lib/ini: remove unused parameters in unmarshalShulhan
The rtype and rval parameters are never used inside the unmarshal method.
2023-05-20all: remove any usage of debug.Value in all packagesShulhan
Using global debug value for all packages turns out is not a good idea.
2022-09-21lib/ini: add example for marshaling slice inside map[string]TShulhan
While at it, clean up some codes to make it more readable and debug-able.
2022-07-27lib/ini: fix parsing and saving multi line variablesShulhan
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.
2022-07-25lib/ini: export the function to parse tagShulhan
2022-07-23lib/ini: support escaped double-quote and colon in tag subsectionShulhan
A colon `:` is escaped using double backslash `\\`, for example `a:b\\:c:d` contains section `a`, subsection `b:c`, and variable `d`. A double quote `"` is escaped using triple backslash, for example `\\\"`.
2022-07-22lib/ini: handle marshaling slice of time.TimeShulhan
2022-07-22lib/ini: fix marshaling pointer to nil fieldShulhan
If the field is pointer, the code will thrown panic if its point to nil struct or print "<invalid reflct.Value>" for String.
2022-04-19lib/ini: fix panic when marshaling unexported field with type structShulhan
While at it, split the example for marshaling and unmarshaling struct into separate examples.
2022-04-18lib/ini: implement marshaling and unmarshaling map with struct elementShulhan
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.
2022-02-06lib/ini: make the Marshal on map field sorted by keysShulhan
Given the following struct, type ADT struct { Amap map[string]string `ini:"section:sub"` } and ini text, [test "map"] c = 3 b = 2 a = 1 Unmarshal-ing the text into ADT and then Marshal-ing it again will result in unpredictable keys order. This changes fix this issue by sorting the keys on ADT.Amap on Marshal-ing, to make the written output predictable.
2021-03-03ini: fix marshaling slice of pointer to structShulhan
In case the root struct contains field like []*T, it should be marshalled the same as []T.
2021-02-28ini: add support for marshaling pointer to struct and to time.TimeShulhan
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>
2021-02-28ini: refactoring unmarshal functionShulhan
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.
2021-02-25ini: add support for marshaling slice of structShulhan
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
2020-06-06all: use default linter optionsShulhan
2020-05-16all: fix and suppress linter warningsShulhan
2020-05-16ini: add method UnsetAllShulhan
The UnsetAll method will remove all variables in section and/or subsection that match with the key.
2020-05-16ini: fix inconsistencies between empty string and boolean trueShulhan
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.
2020-05-16ini: add method to Unmarshal ini values to structShulhan
2020-02-13all: suppress false-positive linter warningsShulhan
2019-10-24ini: add method GetsUniq and ValsUniq that return uniq values onlyShulhan
2019-10-24ini: change Gets return as is, with duplicate valuesShulhan
Previously, Gets return uniq, non-duplicate values. This changes make the Gets return the values as is.
2019-10-16ini: support marshaling and unmarshaling embedded structsShulhan
2019-10-15ini: support marshaling and unmarshal time.TimeShulhan
2019-10-15ini: support marshaling and unmarshaling time.DurationShulhan
2019-09-10ini: check for possible nil variable on WriteShulhan
2019-09-10ini: write the readed ini object only if debug level is 3 on OpenShulhan
2019-07-16lib/ini: add function to unmarshal text into structShulhan
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.
2019-07-16lib/ini: add function to marshal struct into stream of ini textShulhan
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.
2019-07-09ini: add an empty line before section statementShulhan
For readibility, each section should start with an empty line.
2019-06-18ini: create new section or variable if not exist on SetShulhan
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.
2019-06-14all: fix nolint formatShulhan
The valid syntax to suppress linter warnings is "//nolint:<name>" with no space between comment and "nolint" and between ":". Also, we move the placement of nolint directive to the top of statements for multiple nolint in the same scope. While at it, fix and supress some linter warnings.
2019-06-07ini: add method to get section object by section and/or subsection nameShulhan
2019-06-02ini: add method Vars that return all variables as mapShulhan
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.
2019-06-02ini: add parameter section and subsection nameShulhan
If section name is not empty, only the keys will be listed in the map.
2019-05-26ini: add methods to support templatingShulhan
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.
2019-05-26ini: add method to add, set, and unset variableShulhan
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.