aboutsummaryrefslogtreecommitdiffstats
path: root/internal/configloader/configloader.go
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2025-07-19 17:40:13 -0400
committerEugene Triguba <eugenetriguba@gmail.com>2025-07-19 17:40:13 -0400
commitd2a6ba3ff629587646eeb7741ded30f78a52f446 (patch)
tree8f9d8c0ffd5d71d92f0337d4b7f021784566455a /internal/configloader/configloader.go
parentTidy up the test.sh tool script (diff)
downloadcli-d2a6ba3ff629587646eeb7741ded30f78a52f446.zip
Replace envconfig with envelope
Diffstat (limited to 'internal/configloader/configloader.go')
-rw-r--r--internal/configloader/configloader.go33
1 files changed, 20 insertions, 13 deletions
diff --git a/internal/configloader/configloader.go b/internal/configloader/configloader.go
index 0f724a6..842dcfb 100644
--- a/internal/configloader/configloader.go
+++ b/internal/configloader/configloader.go
@@ -13,10 +13,11 @@ import (
"fmt"
"os"
"path/filepath"
+ "reflect"
"runtime"
+ "git.sr.ht/~eugenetriguba/envelope"
"github.com/BurntSushi/toml"
- "github.com/kelseyhightower/envconfig"
)
type VersionStyle string
@@ -41,26 +42,32 @@ var (
// This can come from the TOML file or environment variables,
// with environment variables taking precedence.
type Config struct {
- Migrations MigrationsConfig `toml:"migrations"`
+ Migrations MigrationsConfig `toml:"migrations" env:"BOLT_MIGRATIONS"`
// Information related to how to connect to the database
// that is desired to run migrations against.
- Connection ConnectionConfig `toml:"database"`
+ Connection ConnectionConfig `toml:"database" env:"BOLT_DB"`
}
type MigrationsConfig struct {
- DirectoryPath string `toml:"directory_path" envconfig:"BOLT_MIGRATIONS_DIR_PATH"`
- VersionStyle VersionStyle `toml:"version_style" envconfig:"BOLT_MIGRATIONS_VERSION_STYLE"`
+ DirectoryPath string `toml:"directory_path" env:"DIR_PATH"`
+ VersionStyle VersionStyle `toml:"version_style" env:"VERSION_STYLE"`
}
type ConnectionConfig struct {
- Host string `toml:"host" envconfig:"BOLT_DB_HOST"`
- Port string `toml:"port" envconfig:"BOLT_DB_PORT"`
- User string `toml:"user" envconfig:"BOLT_DB_USER"`
- Password string `toml:"password" envconfig:"BOLT_DB_PASSWORD"`
- DBName string `toml:"dbname" envconfig:"BOLT_DB_NAME"`
- Driver string `toml:"driver" envconfig:"BOLT_DB_DRIVER"`
- MigrationsTable string `toml:"migrations_table" envconfig:"BOLT_DB_MIGRATIONS_TABLE"`
+ Host string `toml:"host" env:"HOST"`
+ Port string `toml:"port" env:"PORT"`
+ User string `toml:"user" env:"USER"`
+ Password string `toml:"password" env:"PASSWORD"`
+ DBName string `toml:"dbname" env:"NAME"`
+ Driver string `toml:"driver" env:"DRIVER"`
+ MigrationsTable string `toml:"migrations_table" env:"MIGRATIONS_TABLE"`
+}
+
+func init() {
+ envelope.RegisterTypeParser(reflect.TypeOf(VersionStyleSequential), envelope.TypeParserFunc(func(value string) (any, error) {
+ return VersionStyle(value), nil
+ }))
}
func NewConfig() (*Config, error) {
@@ -85,7 +92,7 @@ func NewConfig() (*Config, error) {
}
}
- err = envconfig.Process("", &cfg)
+ err = envelope.LoadFromEnv(&cfg)
if err != nil {
return nil, err
}