Env from file
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kekskurse 2022-01-15 00:39:38 +01:00
parent 520ea1f3ca
commit be9ad98f58
Signed by: kekskurse
GPG key ID: 728ACCB59341E7E4

10
main.go
View file

@ -3,6 +3,7 @@ package main
import ( import (
"database/sql" "database/sql"
"embed" "embed"
"errors"
"github.com/flamego/captcha" "github.com/flamego/captcha"
"github.com/flamego/cors" "github.com/flamego/cors"
"github.com/flamego/flamego" "github.com/flamego/flamego"
@ -94,10 +95,19 @@ func s3Connect() {
log.Debug().Msg("Finish create s3 client") log.Debug().Msg("Finish create s3 client")
} }
func loadEnvConfig() { func loadEnvConfig() {
if _, err := os.Stat(".env"); err == nil {
err := godotenv.Load() err := godotenv.Load()
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Error loading .env file") log.Fatal().Err(err).Msg("Error loading .env file")
} }
} else if errors.Is(err, os.ErrNotExist) {
log.Info().Msg("No .env file found")
} else {
log.Fatal().Err(err).Msg("Error load config from env")
}
} }
func main() { func main() {