Initial commit

This commit is contained in:
2024-08-30 11:25:28 +12:00
commit 0cd89c0707
31 changed files with 1470 additions and 0 deletions

38
internal/config/init.go Normal file
View File

@@ -0,0 +1,38 @@
package config
import (
"strings"
"github.com/spf13/viper"
"hub.cybercinch.nz/guisea/go-template/internal/app"
"hub.cybercinch.nz/guisea/go-template/internal/filesystem"
"hub.cybercinch.nz/guisea/go-template/internal/where"
)
// ConfigFormat is the format of the config file
// Available options are: json, yaml, toml
const ConfigFormat = "yaml"
var EnvKeyReplacer = strings.NewReplacer(".", "_")
func Init() error {
viper.SetConfigName(app.Name)
viper.SetConfigType(ConfigFormat)
viper.SetFs(filesystem.Api())
viper.AddConfigPath(where.Config())
viper.SetTypeByDefaultValue(true)
viper.SetEnvPrefix(app.Name)
viper.SetEnvKeyReplacer(EnvKeyReplacer)
setDefaults()
err := viper.ReadInConfig()
switch err.(type) {
case viper.ConfigFileNotFoundError:
// Use defaults then
return nil
default:
return err
}
}