Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
fix(api/get): fix concurrent map writes error
Browse files Browse the repository at this point in the history
Signed-off-by: qwqcode <[email protected]>
  • Loading branch information
qwqcode committed Feb 3, 2023
1 parent 54ec348 commit 19c6c9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.385
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tms v1.0.385
github.com/tidwall/gjson v1.11.0
github.com/vmihailenco/msgpack v4.0.4+incompatible
github.com/x-cray/logrus-prefixed-formatter v0.5.2
github.com/yuin/goldmark v1.4.0
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838
Expand Down Expand Up @@ -118,7 +119,6 @@ require (
github.com/utahta/go-linenotify v0.5.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
Expand Down
10 changes: 7 additions & 3 deletions http/a_resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ func GetApiPublicConfDataMap(c echo.Context) Map {
imgUpload = true // 管理员始终允许上传图片
}

frontendConf := config.Instance.Frontend
if frontendConf == nil {
frontendConf = make(map[string]interface{})
frontendConfSrc := config.Instance.Frontend
if frontendConfSrc == nil {
frontendConfSrc = make(map[string]interface{})
}

frontendConf := make(map[string]interface{})
CopyStruct(&frontendConfSrc, &frontendConf)

frontendConf["imgUpload"] = &imgUpload

return Map{
Expand Down
13 changes: 13 additions & 0 deletions http/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/labstack/echo/v4"
"github.com/mitchellh/mapstructure"
"github.com/sirupsen/logrus"
"github.com/vmihailenco/msgpack"
)

type Map = map[string]interface{}
Expand Down Expand Up @@ -101,3 +102,15 @@ func CheckIsAllowed(c echo.Context, name string, email string, page model.Page,

return true, nil
}

func CopyStruct(src *map[string]interface{}, dest *map[string]interface{}) error {
b, err := msgpack.Marshal(src)
if err != nil {
return err
}
err = msgpack.Unmarshal(b, dest)
if err != nil {
return err
}
return nil
}

0 comments on commit 19c6c9e

Please sign in to comment.