diff --git a/.gitignore b/.gitignore index e69de29..2eea525 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/internal/pkg/env/env.go b/internal/pkg/env/env.go new file mode 100644 index 0000000..9370474 --- /dev/null +++ b/internal/pkg/env/env.go @@ -0,0 +1,28 @@ +package env + +import ( + "os" + + "github.com/joho/godotenv" +) + +func init() { + env := os.Getenv("FASTBIN_ENV") + if env == "" { + env = "development" + } + + godotenv.Load(".env." + env + ".local") + if env != "test" { + godotenv.Load(".env.local") + } + godotenv.Load(".env." + env) + godotenv.Load() +} + +func GetEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} diff --git a/syntax.env b/syntax.env new file mode 100644 index 0000000..3a6963a --- /dev/null +++ b/syntax.env @@ -0,0 +1,7 @@ +API_PORT=8080 +WEB_PORT=8081 +DB_HOST=localhost +DB_PORT=5432 +DB_DATABASE=fastbin +DB_USERNAME=username +DB_PASSWORD=password \ No newline at end of file