|
@@ -35,7 +35,6 @@ func (this *BaseController) AllowCross() { |
|
@@ -35,7 +35,6 @@ func (this *BaseController) AllowCross() { |
35
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
35
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
36
|
//this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "uid, token,jwt, deviceid, appid,Content-Type,Authorization,from")
|
36
|
//this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "uid, token,jwt, deviceid, appid,Content-Type,Authorization,from")
|
37
|
this.Ctx.WriteString("")
|
37
|
this.Ctx.WriteString("")
|
38
|
-
|
|
|
39
|
}
|
38
|
}
|
40
|
|
39
|
|
41
|
func (this *BaseController) Prepare() {
|
40
|
func (this *BaseController) Prepare() {
|
|
@@ -54,26 +53,11 @@ func (this *BaseController) Prepare() { |
|
@@ -54,26 +53,11 @@ func (this *BaseController) Prepare() { |
54
|
this.Query[k] = input.Get(k)
|
53
|
this.Query[k] = input.Get(k)
|
55
|
}
|
54
|
}
|
56
|
if this.Ctx.Input.RequestBody != nil {
|
55
|
if this.Ctx.Input.RequestBody != nil {
|
57
|
- // contentType := this.Ctx.Input.Header("Content-type")
|
|
|
58
|
- // if strings.HasPrefix(contentType, "application/json") {
|
|
|
59
|
this.ByteBody = this.Ctx.Input.RequestBody[:]
|
56
|
this.ByteBody = this.Ctx.Input.RequestBody[:]
|
60
|
if len(this.ByteBody) < 1 {
|
57
|
if len(this.ByteBody) < 1 {
|
61
|
this.ByteBody = []byte("{}")
|
58
|
this.ByteBody = []byte("{}")
|
62
|
}
|
59
|
}
|
63
|
- this.RequestHead = &RequestHead{}
|
|
|
64
|
- this.RequestHead.Token = this.Ctx.Input.Header("token")
|
|
|
65
|
- this.RequestHead.Version = this.Ctx.Input.Header("version")
|
|
|
66
|
- this.RequestHead.Os = this.Ctx.Input.Header("os")
|
|
|
67
|
- this.RequestHead.From = this.Ctx.Input.Header("from")
|
|
|
68
|
- this.RequestHead.Screen = this.Ctx.Input.Header("screen")
|
|
|
69
|
- this.RequestHead.Model = this.Ctx.Input.Header("model")
|
|
|
70
|
- this.RequestHead.Channel = this.Ctx.Input.Header("channel")
|
|
|
71
|
- this.RequestHead.Net = this.Ctx.Input.Header("net")
|
|
|
72
|
- this.RequestHead.DeviceId = this.Ctx.Input.Header("deviceid")
|
|
|
73
|
- this.RequestHead.Uid, _ = strconv.ParseInt(this.Ctx.Input.Header("uid"), 10, 64)
|
|
|
74
|
- this.RequestHead.AppId, _ = strconv.Atoi(this.Ctx.Input.Header("appid"))
|
|
|
75
|
- this.RequestHead.LoginIp = this.Ctx.Input.IP()
|
|
|
76
|
- this.RequestHead.Jwt = this.Ctx.Input.Header("jwt")
|
60
|
+ this.RequestHead = this.GetRequestHead()
|
77
|
this.RequestHead.SetRequestId(fmt.Sprintf("%v.%v.%s",this.RequestHead.Uid,time.GetTimeByYyyymmddhhmmss(),this.Ctx.Request.URL))
|
61
|
this.RequestHead.SetRequestId(fmt.Sprintf("%v.%v.%s",this.RequestHead.Uid,time.GetTimeByYyyymmddhhmmss(),this.Ctx.Request.URL))
|
78
|
log.Info(fmt.Sprintf("====>Recv data from uid(%d) client:\nHeadData: %s\nRequestId:%s BodyData: %s", this.RequestHead.Uid, this.Ctx.Request.Header,this.RequestHead.GetRequestId(), string(this.ByteBody)))
|
62
|
log.Info(fmt.Sprintf("====>Recv data from uid(%d) client:\nHeadData: %s\nRequestId:%s BodyData: %s", this.RequestHead.Uid, this.Ctx.Request.Header,this.RequestHead.GetRequestId(), string(this.ByteBody)))
|
79
|
}
|
63
|
}
|
|
@@ -98,6 +82,24 @@ func (this *BaseController) Prepare() { |
|
@@ -98,6 +82,24 @@ func (this *BaseController) Prepare() { |
98
|
}
|
82
|
}
|
99
|
}
|
83
|
}
|
100
|
|
84
|
|
|
|
85
|
+func (this *BaseController)GetRequestHead()*RequestHead{
|
|
|
86
|
+ reqHead := &RequestHead{}
|
|
|
87
|
+ reqHead.Token = this.Ctx.Input.Header("token")
|
|
|
88
|
+ reqHead.Version = this.Ctx.Input.Header("version")
|
|
|
89
|
+ reqHead.Os = this.Ctx.Input.Header("os")
|
|
|
90
|
+ reqHead.From = this.Ctx.Input.Header("from")
|
|
|
91
|
+ reqHead.Screen = this.Ctx.Input.Header("screen")
|
|
|
92
|
+ reqHead.Model = this.Ctx.Input.Header("model")
|
|
|
93
|
+ reqHead.Channel = this.Ctx.Input.Header("channel")
|
|
|
94
|
+ reqHead.Net = this.Ctx.Input.Header("net")
|
|
|
95
|
+ reqHead.DeviceId = this.Ctx.Input.Header("deviceid")
|
|
|
96
|
+ reqHead.Uid, _ = strconv.ParseInt(this.Ctx.Input.Header("uid"), 10, 64)
|
|
|
97
|
+ reqHead.AppId, _ = strconv.Atoi(this.Ctx.Input.Header("appid"))
|
|
|
98
|
+ reqHead.LoginIp = this.Ctx.Input.IP()
|
|
|
99
|
+ reqHead.Jwt = this.Ctx.Input.Header("jwt")
|
|
|
100
|
+ return reqHead
|
|
|
101
|
+}
|
|
|
102
|
+
|
101
|
func (this *BaseController) Resp(msg *Message) {
|
103
|
func (this *BaseController) Resp(msg *Message) {
|
102
|
|
104
|
|
103
|
this.Data["json"] = msg
|
105
|
this.Data["json"] = msg
|
|
@@ -105,11 +107,9 @@ func (this *BaseController) Resp(msg *Message) { |
|
@@ -105,11 +107,9 @@ func (this *BaseController) Resp(msg *Message) { |
105
|
}
|
107
|
}
|
106
|
|
108
|
|
107
|
func (this *BaseController) Finish() {
|
109
|
func (this *BaseController) Finish() {
|
108
|
-
|
|
|
109
|
if this.Ctx.Input.Method() == "OPTIONS" {
|
110
|
if this.Ctx.Input.Method() == "OPTIONS" {
|
110
|
return
|
111
|
return
|
111
|
}
|
112
|
}
|
112
|
-
|
|
|
113
|
strByte, _ := json.Marshal(this.Data["json"])
|
113
|
strByte, _ := json.Marshal(this.Data["json"])
|
114
|
length := len(strByte)
|
114
|
length := len(strByte)
|
115
|
if length > 5000 {
|
115
|
if length > 5000 {
|