Go to file
Sean Hickey c14e0dfcab Minor doc tweaks. v0.0.2 2022-02-27 02:12:55 -08:00
.gitignore Minor doc tweaks. v0.0.2 2022-02-27 02:12:55 -08:00
License.md Minor doc tweaks. v0.0.2 2022-02-27 02:12:55 -08:00
Makefile Minor doc tweaks. v0.0.2 2022-02-27 02:12:55 -08:00
Readme.md Minor doc tweaks. v0.0.2 2022-02-27 02:12:55 -08:00
go.mod Rename to gosimpleconf 2022-02-21 22:47:36 -08:00
gosimpleconf.go Minor doc tweaks. v0.0.2 2022-02-27 02:12:55 -08:00
gosimpleconf_test.go Minor doc tweaks. v0.0.2 2022-02-27 02:12:55 -08:00

Readme.md

gosimpleconf

go get gitea.wisellama.rocks/Wisellama/gosimpleconf@v0.0.2

This is a small library for parsing super simple configuration files.

It expects a file with the following format:

  • Lines with key-values pairs separated by = (e.g. foo = bar)
  • Lines that start with # are ignored (used for comments)
  • Empty and whitespace-only lines are ignore
  • Lines with data that don't have an = will cause an error.

The key-values pairs are simply parsed as strings and plopped into a map for you to do whatever your program wants with them. If you need a value to not be a string, you will have to convert the value from a string as needed for your program (e.g. using the strconv library).

Example

Here's an example config file file.conf

url = www.wisellama.rocks
number_of_widgets = 1337
pi = 3.141592653589793238462643383
environment = production

Then to load that config file into a map:

configMap, err := gosimpleconf.Load("file.conf")

Then everything is a string. You can parse it as needed.

var piStr string = configMap["pi"]
pi, err := strconv.ParseFloat(value, 64)

Why?

I've always seen configuration files similar to this show up in Unix-like systems and programs, but it doesn't seem to be fully standardized under a real name other than just "conf files". The closest I've seen are INI files, but those don't seem to fit the style I was looking for (they don't use # for comments and they support sections in square brackets [section]).

Instead, I just wanted the bare minimum configuration format of foo = bar on each line with # for comments. So that's what this library does.

This project looks abandoned

This library is so simple that I almost never expect to need to update it unless Go fundamentally breaks the language in the future. So while the project may eventually look like it has been abandoned, it is rather simply "complete". (gasp I know, such a rare thing in the software world).

License

This project is licensed under the 2-Clause BSD License (a permissive open source license). See License.md for the full text.