|
@@ -7,6 +7,7 @@ import (
|
7
|
7
|
"spaceofcheng/services/models/model"
|
8
|
8
|
"spaceofcheng/services/service/bodycheck"
|
9
|
9
|
"spaceofcheng/services/utils"
|
|
10
|
+ "sync"
|
10
|
11
|
|
11
|
12
|
"github.com/astaxie/beego"
|
12
|
13
|
)
|
|
@@ -15,6 +16,8 @@ import (
|
15
|
16
|
// 临时的解决方案是放到全局单例对象中
|
16
|
17
|
var qrCodes map[string]string
|
17
|
18
|
|
|
19
|
+var mtx *sync.Mutex
|
|
20
|
+
|
18
|
21
|
// BodyCheckController 商品
|
19
|
22
|
type BodyCheckController struct {
|
20
|
23
|
serv *bodycheck.BodyCheckServ
|
|
@@ -67,8 +70,15 @@ func (c *BodyCheckController) GetCheckByUser() {
|
67
|
70
|
|
68
|
71
|
// PostCheckResult 测量结果返回
|
69
|
72
|
func (c *BodyCheckController) PostCheckResult() {
|
|
73
|
+ // 防止并发
|
|
74
|
+ mtx.Lock()
|
|
75
|
+
|
70
|
76
|
r := c.Ctx.Request
|
71
|
|
- defer r.Body.Close()
|
|
77
|
+ defer func() {
|
|
78
|
+ r.Body.Close()
|
|
79
|
+ mtx.Unlock()
|
|
80
|
+ }()
|
|
81
|
+
|
72
|
82
|
con, _ := ioutil.ReadAll(r.Body) //获取post的数据
|
73
|
83
|
|
74
|
84
|
var formVal map[string]interface{}
|
|
@@ -98,4 +108,5 @@ func (c *BodyCheckController) PostCheckResult() {
|
98
|
108
|
|
99
|
109
|
func init() {
|
100
|
110
|
qrCodes = make(map[string]string)
|
|
111
|
+ mtx = new(sync.Mutex)
|
101
|
112
|
}
|