mirror of
https://github.com/tiennm99/MTTools.git
synced 2026-08-13 07:22:03 +00:00
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:
@@ -8,6 +8,8 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
_ "github.com/tiennm99/go-util/internal/env"
|
||||
)
|
||||
|
||||
// org represents a Gitea organization.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
module github.com/tiennm99/go-util
|
||||
|
||||
go 1.26.1
|
||||
|
||||
require github.com/joho/godotenv v1.5.1 // indirect
|
||||
|
||||
@@ -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=
|
||||
Vendored
+16
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user