fix: load env once

This commit is contained in:
lilong.129
2025-04-21 22:50:00 +08:00
parent 70a8ee01f7
commit 9418c651f4
3 changed files with 8 additions and 5 deletions

View File

@@ -30,12 +30,12 @@ type Config struct {
}
var (
globalConfig *Config
once sync.Once
globalConfig *Config
getConfigOnce sync.Once
)
func GetConfig() *Config {
once.Do(func() {
getConfigOnce.Do(func() {
cfg := &Config{
StartTime: time.Now(),
}

View File

@@ -5,15 +5,18 @@ import (
"os"
"path/filepath"
"strconv"
"sync"
"github.com/joho/godotenv"
"github.com/rs/zerolog/log"
)
var loadEnvOnce sync.Once
// LoadEnv loads environment variables from .env file
// it will search for .env file from current working directory upward recursively
func LoadEnv() (err error) {
once.Do(func() {
loadEnvOnce.Do(func() {
// get current working directory
var cwd string
cwd, err = os.Getwd()

View File

@@ -1 +1 @@
v5.0.0-beta-2504212133
v5.0.0-beta-2504212250