cointop-sh / cointop

A fast and lightweight interactive terminal based UI application for tracking cryptocurrencies 🚀
https://cointop.sh
Apache License 2.0
3.94k stars 309 forks source link

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

Open lyricnz opened 2 years ago

lyricnz commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

(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)