feat: auto-load .env via shared internal/env package

Add godotenv dependency and internal/env init loader so all cmd/
scripts get .env vars loaded automatically via blank import.
This commit is contained in:
2026-04-13 09:13:24 +07:00
parent 09a7630a1c
commit 1ff7e154bb
4 changed files with 22 additions and 0 deletions
+2
View File
@@ -8,6 +8,8 @@ import (
"net/http"
"os"
"strings"
_ "github.com/tiennm99/go-util/internal/env"
)
// org represents a Gitea organization.
+2
View File
@@ -1,3 +1,5 @@
module github.com/tiennm99/go-util
go 1.26.1
require github.com/joho/godotenv v1.5.1 // indirect
+2
View File
@@ -0,0 +1,2 @@
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
+16
View File
@@ -0,0 +1,16 @@
// Package env loads .env files on init so all cmd/ scripts get env vars automatically.
// Usage: import _ "github.com/tiennm99/go-util/internal/env"
package env
import (
"os"
"github.com/joho/godotenv"
)
func init() {
// Skip if .env doesn't exist; load if it does.
if _, err := os.Stat(".env"); err == nil {
_ = godotenv.Load()
}
}