diff --git a/cmd/darsrec/main.go b/cmd/darsrec/main.go index 5abc064..bfc45a4 100644 --- a/cmd/darsrec/main.go +++ b/cmd/darsrec/main.go @@ -2,10 +2,16 @@ package main import ( "fmt" - rec2 "github.com/ccil-kbw/robot/pkg/rec" "os" + + environment "github.com/ccil-kbw/robot/internal/environment" + rec2 "github.com/ccil-kbw/robot/pkg/rec" ) +func init() { + environment.LoadEnvironmentVariables() +} + // TODO: Swap all this as a darsRec.StartServer() func main() { diff --git a/cmd/discord_bot/main.go b/cmd/discord_bot/main.go index 1f6887c..d894a23 100644 --- a/cmd/discord_bot/main.go +++ b/cmd/discord_bot/main.go @@ -1,13 +1,15 @@ package main import ( + "log" + "github.com/caarlos0/env/v11" + environment "github.com/ccil-kbw/robot/internal/environment" "github.com/ccil-kbw/robot/pkg/discord" - "github.com/joho/godotenv" "go.uber.org/zap" - "log" ) +// TODO: Should Types have a folder of their own? type config struct { Environment string `env:"ENVIRONMENT" envDefault:"dev"` DiscordServerID string `env:"DISCORD_SERVER_ID"` @@ -21,7 +23,7 @@ var ( ) func init() { - loadEnvs() + environment.LoadEnvironmentVariables() loadConfig() initializeLogger() } @@ -31,15 +33,6 @@ func main() { bot.StartBot() } -func loadEnvs() { - err := godotenv.Load() - if err != nil { - log.Println(".env not present, using process envs and defaults") - } else { - log.Println(".env loaded") - } -} - func loadConfig() { if err := env.Parse(&cfg); err != nil { log.Fatalf("%+v\n", err) diff --git a/cmd/monolith/main.go b/cmd/monolith/main.go index 845ac06..e4a30e5 100644 --- a/cmd/monolith/main.go +++ b/cmd/monolith/main.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "log" + environment "github.com/ccil-kbw/robot/internal/environment" "github.com/ccil-kbw/robot/pkg/discord" rec2 "github.com/ccil-kbw/robot/pkg/rec" @@ -13,8 +13,6 @@ import ( "time" "go.uber.org/zap" - - "github.com/joho/godotenv" ) var ( @@ -45,7 +43,7 @@ var ( ) func init() { - loadEnvs() + environment.LoadEnvironmentVariables() } func main() { @@ -137,12 +135,3 @@ func startServerWithRetry(host string, password string, data *rec2.RecordConfigD } } } - -func loadEnvs() { - err := godotenv.Load() - if err != nil { - log.Println(".env not present, using process envs and defaults") - } else { - log.Println(".env loaded") - } -} diff --git a/internal/environment/environment.go b/internal/environment/environment.go new file mode 100644 index 0000000..faf41ec --- /dev/null +++ b/internal/environment/environment.go @@ -0,0 +1,16 @@ +package environment + +import ( + "log" + + "github.com/joho/godotenv" +) + +func LoadEnvironmentVariables() { + err := godotenv.Load() + if err != nil { + log.Println(".env not present, using process envs and defaults") + } else { + log.Println(".env loaded") + } +}