aboutsummaryrefslogtreecommitdiff
path: root/lib/ini/reader.go
AgeCommit message (Collapse)Author
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-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-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
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-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-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
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)
2021-03-01ini: increase the debug value minimum to 3Shulhan
The debug level 1 and 2 is used by application level.
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.
2019-09-27all: remove unnecessary trailing newlineShulhan
2019-09-12ini: set variable with "=" without a value default to empty stringShulhan
Previously, a variable end with "=" will have value set to "true". For example, [section] var = will set the "var" value to string "true". This changes make the variable that end with "=" without any value to be an empty string, so "var" value is equal to "".
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: escape the variable value when printing with StringShulhan
If the variable is quoted, the value must be escaped so the following character are allowed: '\b', '\n', '\t', '\\', and '\"'.
2019-05-26ini: replace multiple ifs conditions with switch statementShulhan
This is the third part of refactoring ini package. The change affect on how variable value being fetched and formatted.
2019-05-25ini: rename varModeXXX to lineModeXXXShulhan
This is the second part of refactoring to provide clean and readable code.
2019-05-25ini: unexport Variable and SectionShulhan
This is the first part to refactoring ini package to provide a clean and simple API.
2019-02-25ini: unexport the readerShulhan
Instead of using reader, call the new function Parse(), to parse INI formatted text.
2018-11-30all: fix and suppress linter warnings on long linesShulhan
2018-11-30all: minimize and suppress linter warnings for global variablesShulhan
2018-11-30all: fix linter warnings on naked returnShulhan
2018-11-29lib/ini: use package debug for initializing debug from environmentShulhan
2018-11-29all: fix warnings from lintersShulhan
2018-08-21lib/ini: allow underscore in variable nameShulhan
2018-08-17lib/ini: allow dot character '.' on variable nameShulhan
2018-08-17lib/ini: remove unused "nolint" tagShulhan
2018-05-18reader: do not add empty variable on end of fileShulhan
2018-05-13Export section's name and their lower case nameShulhan
2018-05-13reader: fix wrong line number on error messageShulhan
2018-05-13Replace field type in Section and Variable from []byte to stringShulhan
2018-05-13Export variable key and valueShulhan
2018-05-13Export Section sub, line number, and variablesShulhan
2018-05-13section: add field for line numberShulhan
2018-05-13section: change type from alias to structShulhan
2018-05-12Add copyright and license informationShulhan
2018-05-11reader: fix value with escaped character "\b", "\n", and "\t"Shulhan
2018-05-11Add method to manipulate variable in SectionShulhan
Also, * Export variable type * Export section type * Set print format if variable's format is empty
2018-05-10reader: return Ini instance on ParseFile and ParseShulhan
2018-05-10Refactor parser using bytes.ReaderShulhan
Previous benchmark result (22dcd07 Move buffer to reader), BenchmarkParse-2 500 19534400 ns/op 4656335 B/op 81163 allocs/op New benchmark result, BenchmarkParse-2 20000 71120 ns/op 35368 B/op 549 allocs/op
2018-05-08Fix comment grammarShulhan
Use "will" only on function to method that may return with error or not true.
2018-05-08Add getter methodShulhan
2018-05-08reader.parseSection: convert section to lowercaseShulhan
2018-05-08Change method signatures between Ini and ReaderShulhan
2018-05-08Move buffer to readerShulhan