From 9418c651f42c57caeeeb6c2d6637e3919b2b2948 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Mon, 21 Apr 2025 22:50:00 +0800 Subject: [PATCH] fix: load env once --- internal/config/config.go | 6 +++--- internal/config/env.go | 5 ++++- internal/version/VERSION | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 24e82ae0..e7b7d3b3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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(), } diff --git a/internal/config/env.go b/internal/config/env.go index 1972470a..a9b830d0 100644 --- a/internal/config/env.go +++ b/internal/config/env.go @@ -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() diff --git a/internal/version/VERSION b/internal/version/VERSION index 12546ba5..0bc4f4c1 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2504212133 +v5.0.0-beta-2504212250