fix(serialization): use replace os.LookupEnv with env.LookupEnv

This commit is contained in:
yusing
2025-10-15 00:12:17 +08:00
parent e13b18621d
commit b09bfd6c1e

View File

@@ -15,6 +15,7 @@ import (
"github.com/puzpuzpuz/xsync/v4" "github.com/puzpuzpuz/xsync/v4"
"github.com/yusing/godoxy/internal/utils" "github.com/yusing/godoxy/internal/utils"
gi "github.com/yusing/gointernals" gi "github.com/yusing/gointernals"
"github.com/yusing/goutils/env"
gperr "github.com/yusing/goutils/errs" gperr "github.com/yusing/goutils/errs"
strutils "github.com/yusing/goutils/strings" strutils "github.com/yusing/goutils/strings"
) )
@@ -603,7 +604,9 @@ func substituteEnv(data []byte) ([]byte, gperr.Error) {
envError := gperr.NewBuilder("env substitution error") envError := gperr.NewBuilder("env substitution error")
data = envRegex.ReplaceAllFunc(data, func(match []byte) []byte { data = envRegex.ReplaceAllFunc(data, func(match []byte) []byte {
varName := string(match[2 : len(match)-1]) varName := string(match[2 : len(match)-1])
env, ok := os.LookupEnv(varName) // NOTE: use env.LookupEnv instead of os.LookupEnv to support environment variable prefixes
// like ${API_ADDR} will lookup for GODOXY_API_ADDR, GOPROXY_API_ADDR and API_ADDR.
env, ok := env.LookupEnv(varName)
if !ok { if !ok {
envError.Addf("%s is not set", varName) envError.Addf("%s is not set", varName)
} }