...
|
...
|
@@ -3,8 +3,10 @@ package controllers |
|
|
import (
|
|
|
"crypto/sha256"
|
|
|
"encoding/hex"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego/plugins/cors"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
|
...
|
...
|
@@ -25,6 +27,7 @@ var ( |
|
|
)
|
|
|
|
|
|
type BaseController struct {
|
|
|
Header *protocol.RequestHeader
|
|
|
mybeego.BaseController
|
|
|
}
|
|
|
|
...
|
...
|
@@ -91,7 +94,6 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { |
|
|
}
|
|
|
h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-cid"), 10, 64)
|
|
|
h.UserId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-id"), 10, 64)
|
|
|
log.Debug(common.AssertJson(h))
|
|
|
return h
|
|
|
}
|
|
|
|
...
|
...
|
@@ -258,3 +260,40 @@ var LogRequestData = func(ctx *context.Context) { |
|
|
log.Info("====>Recv data from client:\nHeadData: %v ", hmap)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (this *BaseController) Prepare() {
|
|
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
|
|
|
if this.Ctx.Input.Method() == "OPTIONS" {
|
|
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
|
|
return
|
|
|
}
|
|
|
this.Query = map[string]string{}
|
|
|
input := this.Input()
|
|
|
for k := range input {
|
|
|
this.Query[k] = input.Get(k)
|
|
|
}
|
|
|
if this.Ctx.Input.RequestBody != nil {
|
|
|
this.ByteBody = this.Ctx.Input.RequestBody[:]
|
|
|
if len(this.ByteBody) < 1 {
|
|
|
this.ByteBody = []byte("{}")
|
|
|
}
|
|
|
this.RequestHead = this.GetRequestHead()
|
|
|
this.Header = GetRequestHeader(this.Ctx)
|
|
|
this.Header.SetRequestId(fmt.Sprintf("%v.%v.%s", this.Header.Uid, time.GetTimeByYyyymmddhhmmss(), this.Ctx.Request.URL))
|
|
|
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)))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (this *BaseController) Finish() {
|
|
|
if this.Ctx.Input.Method() == "OPTIONS" {
|
|
|
return
|
|
|
}
|
|
|
strByte, _ := json.Marshal(this.Data["json"])
|
|
|
length := len(strByte)
|
|
|
if length > 5000 {
|
|
|
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])))
|
|
|
} else {
|
|
|
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)))
|
|
|
}
|
|
|
} |
...
|
...
|
|