Added more API documentation

This commit is contained in:
David Allen 2024-07-23 16:18:21 -06:00
parent 2bc3c74277
commit f7b08da064
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
8 changed files with 150 additions and 90 deletions

View file

@ -7,15 +7,19 @@ import (
"github.com/spf13/viper"
)
// LoadConfig() will load a YAML config file at the specified path. There are some general
// considerations about how this is done with spf13/viper:
//
// 1. There are intentionally no search paths set, so config path has to be set explicitly
// 2. No data will be written to the config file from the tool
// 3. Parameters passed as CLI flags and envirnoment variables should always have
// precedence over values set in the config.
func LoadConfig(path string) error {
dir, filename, ext := util.SplitPathForViper(path)
// fmt.Printf("dir: %s\nfilename: %s\nextension: %s\n", dir, filename, ext)
viper.AddConfigPath(dir)
viper.SetConfigName(filename)
viper.SetConfigType(ext)
// ...no search paths set intentionally, so config has to be set explicitly
// ...also, the config file will not save anything
// ...and finally, parameters passed to CLI have precedence over config values
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {