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

View file

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

View file

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

View file

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