Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor config load/save code to be simpler and more declarative #286

Open
lyricnz opened this issue Nov 18, 2021 · 2 comments
Open

Refactor config load/save code to be simpler and more declarative #286

lyricnz opened this issue Nov 18, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@lyricnz
Copy link
Collaborator

lyricnz commented Nov 18, 2021

At the moment there's a lot of code necessary for accessing the configuration file, and updating it is a real headache. We should consider something more declarative, so we can modify more-or-less one place, and have it work properly (load/save etc). Also, coordinating the command-line args and environment variables vs config would be nice.

This probably relates to "Don't store app state in configuration file #238"

@lyricnz lyricnz added the enhancement New feature or request label Nov 18, 2021
@lyricnz
Copy link
Collaborator Author

lyricnz commented Nov 18, 2021

There's a million "configuration frameworks" for golang, but we should try and be careful not to add another poorly maintained (or overly complex/big) upstream just for this.
eg https://reposhub.com/go/configuration

@lyricnz
Copy link
Collaborator Author

lyricnz commented Nov 18, 2021

(not a suggestion - thinking out loud) Some of my workmates suggest:

YMMV, but separating validation from load/parse can often simplify too
Have used this in the past: https://github.com/go-playground/validator

In Go you can get a lot of typing/structure very easily.
If you use https://pkg.go.dev/gopkg.in/yaml.v2#Unmarshal the type/structure is defined in go structs, and the library will expect sequence/mappings and certain YAML values depending on the corresponding struct/field in Go.

Viper looks good, but probably major overkill https://github.com/spf13/viper
And fwiw Cobra could manage/generate our CLI interfaces (but would be refactor without end-user value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant