aboutsummaryrefslogtreecommitdiff
path: root/lib/ini
AgeCommit message (Collapse)Author
11 daysall: apply go fixShulhan
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
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/
2026-01-08lib/ini: improve error message when parsing variable nameShulhan
Display the invalid character in the error message with quote, so space can detected. Also, export the error variable so external caller can detect it using the variable.
2025-02-04all: remove the nolint tagsShulhan
The "nolint" tag is used to ignore lines from being processed by golangci-lint. Since we are not using golangci-lint anymore, now and in the future, those lines can be removed.
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
2025-01-22lib/bytes: replace Copy and Concat with standard libraryShulhan
Since Go 1.20, the standard bytes package have the Copy function. Since Go 1.22, the standard slices package have the Concat function.
2024-09-04all: fix various linter warningsShulhan
While at it, temporary disable gosec due to excessive report for G115, which may be true, but may also break the current working program. We should alter and fix once we can test and make sure that it does not breaks.
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-06all: conform with linter gosec, ineffasign, and makezeroShulhan
Some of warnings from those linter are false positives, so we just annotated them.
2024-03-05all: comply with linter recommendations #3Shulhan
For HTTP server that use TLS, set the minimum TLS version and ReadHeaderTimeout to mitigate slowloris attack. For HTTP client or server that parameterize the use of InsecureSkipVerify, annotate the line with "nolint:gosec" to allow the code pass the check. Library that still use sha1, in example in DKIM and TOTP, skip the warnings by annotating the line with "nolint:gosec". A pointer variable now allocated their address before assigning its value. Any error that returned now wrapped using "%w". Also, replace error checking using [errors.Is] or [errors.As] instead of using equal or not-equal operators. In "lib/http", replace any usage of "math/rand" with "crypto/rand". Any call of [math/big.Rat.SetString] now annotated with "nolint:gosec" since its false positive, the issue has been fixed in Go >= 1.17.7. Any switch case that does not cover the rest of the possible values now handled by adding the cases or by replacing the "default" case with the rest of values.
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-11-12lib/ini: add test for parsing multi line value without spacesShulhan
Multi line values without spaces should not add any space in between.
2023-11-12lib/ini: append variable into section before any empty linesShulhan
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.
2023-11-12lib/ini: update module documentationShulhan
Use "/**/" comment format for simplify editing.
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-09-11lib/ini: remove tag on un-exported struct fieldsShulhan
2023-09-11lib/ini: realign some structs in testShulhan
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)
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-26lib/ini: parse comment as part of formatShulhan
Previously, the comment is parsed and stored separately. This changes make the comment as part of format.
2022-07-26lib/ini: record benchmark result for Parse in separate fileShulhan
While at it, rewrite the benchmark code to call Parse instead of reader.Parse and reset the timer after loading the file.
2022-07-25lib/ini: export the function to parse tagShulhan
2022-07-25lib/test: truncate the last new line at the end of input and outputShulhan
Given the following input and output, >>> input <<< output EOF The input and output content always have new line at the end. This may cause unexpected input or output. If input or output content expecting new line at the end, add two empty lines at the end of it.
2022-07-23lib/test: load test data files with suffix "_test.txt"Shulhan
Previously, the LoadDataDir load all files from directory that have ".txt" extension. This may cause unknown non-test data files loaded and may cause an error. To distinguish it with other text files, inside the directory to be loaded load only the file that has suffix "_test.txt".
2022-07-23lib/ini: convert the Get test using test.DataShulhan
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: refactoring test to use test.DataShulhan
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-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
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-04-06all: replace any usage of ioutil package with os or ioShulhan
Since Go 1.16, the ioutil package has been deprecated. This changes replace any usage that use functions from ioutil package with their replacement from package os or package io.
2022-02-06lib/ini: realign all structsShulhan
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)
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-10-23lib/ini: check for empty string on IsValidVarNameShulhan
2021-10-23lib/ini: add function IsValidVarNameShulhan
The IsValidVarName check if "v" is valid variable name, where the first character must be a letter and the rest should contains only letter, digit, period, hyphen, or underscore. If "v" is valid it will return true.
2021-10-23lib/ini: add example of marshal/unmarshaling of section with subShulhan
This changes also fix the example of field tag on marshaling the map.
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
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-03-01ini: increase the debug value minimum to 3Shulhan
The debug level 1 and 2 is used by application level.