refactor: use maps (#10154)

This commit is contained in:
cui 2025-08-27 10:08:51 +08:00 committed by GitHub
parent e84aa49003
commit c0a0f4c801
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 12 deletions

View file

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"maps"
"math" "math"
"net/http" "net/http"
"os" "os"
@ -1044,11 +1045,11 @@ func copyData(task *task.Task, app model.App, appDetail model.AppDetail, appInst
return return
} }
envPath := path.Join(appDir, ".env") envPath := path.Join(appDir, ".env")
envParams := make(map[string]string, len(req.Params)) var envParams map[string]string
if fileOp.Stat(envPath) { if fileOp.Stat(envPath) {
envs, _ := gotenv.Read(envPath) envs, _ := gotenv.Read(envPath)
for k, v := range envs { if envParams = maps.Clone(envs); envParams == nil {
envParams[k] = v envParams = make(map[string]string)
} }
} }
handleMap(req.Params, envParams) handleMap(req.Params, envParams)

View file

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
fcgiclient "github.com/tomasen/fcgi_client" fcgiclient "github.com/tomasen/fcgi_client"
"maps"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -1092,9 +1093,7 @@ func (r *RuntimeService) UpdatePHPContainer(req request.PHPContainerConfig) erro
} }
newMap := make(map[string]string) newMap := make(map[string]string)
handleMap(create.Params, newMap) handleMap(create.Params, newMap)
for k, v := range newMap { maps.Copy(envs, newMap)
envs[k] = v
}
envs["PANEL_APP_PORT_HTTP"] = runtime.Port envs["PANEL_APP_PORT_HTTP"] = runtime.Port
envStr, err := gotenv.Marshal(envs) envStr, err := gotenv.Marshal(envs)
if err != nil { if err != nil {

View file

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"maps"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@ -522,9 +523,7 @@ func handleParams(create request.RuntimeCreate, projectDir string) (composeConte
newMap := make(map[string]string) newMap := make(map[string]string)
handleMap(create.Params, newMap) handleMap(create.Params, newMap)
for k, v := range newMap { maps.Copy(env, newMap)
env[k] = v
}
envStr, err := gotenv.Marshal(env) envStr, err := gotenv.Marshal(env)
if err != nil { if err != nil {

View file

@ -6,6 +6,7 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io" "io"
"maps"
"net/http" "net/http"
"strings" "strings"
) )
@ -46,9 +47,9 @@ func (d *DigestAuth) Close() error {
} }
func (d *DigestAuth) Clone() Authenticator { func (d *DigestAuth) Clone() Authenticator {
parts := make(map[string]string, len(d.digestParts)) var parts map[string]string
for k, v := range d.digestParts { if parts = maps.Clone(parts); parts == nil {
parts[k] = v parts = make(map[string]string)
} }
return &DigestAuth{user: d.user, pw: d.pw, digestParts: parts} return &DigestAuth{user: d.user, pw: d.pw, digestParts: parts}
} }