|
@@ -3,8 +3,10 @@ package controllers |
|
@@ -3,8 +3,10 @@ package controllers |
3
|
import (
|
3
|
import (
|
4
|
"crypto/sha256"
|
4
|
"crypto/sha256"
|
5
|
"encoding/hex"
|
5
|
"encoding/hex"
|
|
|
6
|
+ "encoding/json"
|
6
|
"fmt"
|
7
|
"fmt"
|
7
|
"github.com/astaxie/beego/plugins/cors"
|
8
|
"github.com/astaxie/beego/plugins/cors"
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
|
8
|
"strconv"
|
10
|
"strconv"
|
9
|
"strings"
|
11
|
"strings"
|
10
|
|
12
|
|
|
@@ -25,6 +27,7 @@ var ( |
|
@@ -25,6 +27,7 @@ var ( |
25
|
)
|
27
|
)
|
26
|
|
28
|
|
27
|
type BaseController struct {
|
29
|
type BaseController struct {
|
|
|
30
|
+ Header *protocol.RequestHeader
|
28
|
mybeego.BaseController
|
31
|
mybeego.BaseController
|
29
|
}
|
32
|
}
|
30
|
|
33
|
|
|
@@ -91,7 +94,6 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { |
|
@@ -91,7 +94,6 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { |
91
|
}
|
94
|
}
|
92
|
h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-cid"), 10, 64)
|
95
|
h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-cid"), 10, 64)
|
93
|
h.UserId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-id"), 10, 64)
|
96
|
h.UserId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-id"), 10, 64)
|
94
|
- log.Debug(common.AssertJson(h))
|
|
|
95
|
return h
|
97
|
return h
|
96
|
}
|
98
|
}
|
97
|
|
99
|
|
|
@@ -258,3 +260,40 @@ var LogRequestData = func(ctx *context.Context) { |
|
@@ -258,3 +260,40 @@ var LogRequestData = func(ctx *context.Context) { |
258
|
log.Info("====>Recv data from client:\nHeadData: %v ", hmap)
|
260
|
log.Info("====>Recv data from client:\nHeadData: %v ", hmap)
|
259
|
}
|
261
|
}
|
260
|
}
|
262
|
}
|
|
|
263
|
+
|
|
|
264
|
+func (this *BaseController) Prepare() {
|
|
|
265
|
+ this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
266
|
+ this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
|
|
|
267
|
+ if this.Ctx.Input.Method() == "OPTIONS" {
|
|
|
268
|
+ this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
|
|
269
|
+ return
|
|
|
270
|
+ }
|
|
|
271
|
+ this.Query = map[string]string{}
|
|
|
272
|
+ input := this.Input()
|
|
|
273
|
+ for k := range input {
|
|
|
274
|
+ this.Query[k] = input.Get(k)
|
|
|
275
|
+ }
|
|
|
276
|
+ if this.Ctx.Input.RequestBody != nil {
|
|
|
277
|
+ this.ByteBody = this.Ctx.Input.RequestBody[:]
|
|
|
278
|
+ if len(this.ByteBody) < 1 {
|
|
|
279
|
+ this.ByteBody = []byte("{}")
|
|
|
280
|
+ }
|
|
|
281
|
+ this.RequestHead = this.GetRequestHead()
|
|
|
282
|
+ this.Header = GetRequestHeader(this.Ctx)
|
|
|
283
|
+ this.Header.SetRequestId(fmt.Sprintf("%v.%v.%s", this.Header.Uid, time.GetTimeByYyyymmddhhmmss(), this.Ctx.Request.URL))
|
|
|
284
|
+ log.Debug(fmt.Sprintf("====>Recv data from uid(%d) ucid(%v) client:\nHeadData: %s\nRequestId:%s BodyData: %s", this.Header.Uid, this.Header.UserId, common.AssertJson(this.Header), this.Header.GetRequestId(), string(this.ByteBody)))
|
|
|
285
|
+ }
|
|
|
286
|
+}
|
|
|
287
|
+
|
|
|
288
|
+func (this *BaseController) Finish() {
|
|
|
289
|
+ if this.Ctx.Input.Method() == "OPTIONS" {
|
|
|
290
|
+ return
|
|
|
291
|
+ }
|
|
|
292
|
+ strByte, _ := json.Marshal(this.Data["json"])
|
|
|
293
|
+ length := len(strByte)
|
|
|
294
|
+ if length > 5000 {
|
|
|
295
|
+ log.Debug(fmt.Sprintf("<====Send to uid(%d) ucid(%v) client: %d byte\nRequestId:%s RspBodyData: %s......", this.Header.Uid, this.Header.UserId, length, this.Header.GetRequestId(), string(strByte[:5000])))
|
|
|
296
|
+ } else {
|
|
|
297
|
+ log.Debug(fmt.Sprintf("<====Send to uid(%d) ucid(%v) client: %d byte\nRequestId:%s RspBodyData: %s", this.Header.Uid, this.Header.UserId, length, this.Header.GetRequestId(), string(strByte)))
|
|
|
298
|
+ }
|
|
|
299
|
+} |