|
@@ -30,7 +30,7 @@ func init() { |
|
@@ -30,7 +30,7 @@ func init() { |
30
|
|
30
|
|
31
|
var DefaultController *BaseController = &BaseController{}
|
31
|
var DefaultController *BaseController = &BaseController{}
|
32
|
|
32
|
|
33
|
-//Valid valid struct
|
33
|
+// Valid valid struct
|
34
|
func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.ResponseMessage) {
|
34
|
func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.ResponseMessage) {
|
35
|
/*校验*/
|
35
|
/*校验*/
|
36
|
var err error
|
36
|
var err error
|
|
@@ -66,7 +66,7 @@ func (this *BaseController) RespH5(msg *protocol.ResponseMessage) { |
|
@@ -66,7 +66,7 @@ func (this *BaseController) RespH5(msg *protocol.ResponseMessage) { |
66
|
this.ServeJSON()
|
66
|
this.ServeJSON()
|
67
|
}
|
67
|
}
|
68
|
|
68
|
|
69
|
-//获取请求头信息
|
69
|
+// 获取请求头信息
|
70
|
func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
|
70
|
func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
|
71
|
h := &protocol.RequestHeader{}
|
71
|
h := &protocol.RequestHeader{}
|
72
|
h.AccessToken = ctx.Input.Header("x-mmm-accesstoken")
|
72
|
h.AccessToken = ctx.Input.Header("x-mmm-accesstoken")
|
|
@@ -79,7 +79,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { |
|
@@ -79,7 +79,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { |
79
|
return h
|
79
|
return h
|
80
|
}
|
80
|
}
|
81
|
|
81
|
|
82
|
-//过滤器
|
82
|
+// 过滤器
|
83
|
func FilterComm(ctx *context.Context) {
|
83
|
func FilterComm(ctx *context.Context) {
|
84
|
if !CheckSign(ctx) {
|
84
|
if !CheckSign(ctx) {
|
85
|
return
|
85
|
return
|
|
@@ -87,7 +87,7 @@ func FilterComm(ctx *context.Context) { |
|
@@ -87,7 +87,7 @@ func FilterComm(ctx *context.Context) { |
87
|
return
|
87
|
return
|
88
|
}
|
88
|
}
|
89
|
|
89
|
|
90
|
-//检查签名
|
90
|
+// 检查签名
|
91
|
func CheckSign(ctx *context.Context) (result bool) {
|
91
|
func CheckSign(ctx *context.Context) (result bool) {
|
92
|
var (
|
92
|
var (
|
93
|
h *protocol.RequestHeader
|
93
|
h *protocol.RequestHeader
|
|
@@ -111,7 +111,7 @@ func CheckSign(ctx *context.Context) (result bool) { |
|
@@ -111,7 +111,7 @@ func CheckSign(ctx *context.Context) (result bool) { |
111
|
return
|
111
|
return
|
112
|
}
|
112
|
}
|
113
|
|
113
|
|
114
|
-//AllowOption 允许跨域请求
|
114
|
+// AllowOption 允许跨域请求
|
115
|
var AllowOption = func(ctx *context.Context) {
|
115
|
var AllowOption = func(ctx *context.Context) {
|
116
|
if ctx.Request.Method != "OPTIONS" {
|
116
|
if ctx.Request.Method != "OPTIONS" {
|
117
|
return
|
117
|
return
|
|
@@ -130,7 +130,7 @@ var AllowOption = func(ctx *context.Context) { |
|
@@ -130,7 +130,7 @@ var AllowOption = func(ctx *context.Context) { |
130
|
return
|
130
|
return
|
131
|
}
|
131
|
}
|
132
|
|
132
|
|
133
|
-//LogRequestData Before Router
|
133
|
+// LogRequestData Before Router
|
134
|
var LogRequestData = func(ctx *context.Context) {
|
134
|
var LogRequestData = func(ctx *context.Context) {
|
135
|
log.Info("====>Recv Request:%s", ctx.Input.URI())
|
135
|
log.Info("====>Recv Request:%s", ctx.Input.URI())
|
136
|
hmap := map[string]string{
|
136
|
hmap := map[string]string{
|
|
@@ -183,12 +183,13 @@ func (this *BaseController) Finish() { |
|
@@ -183,12 +183,13 @@ func (this *BaseController) Finish() { |
183
|
|
183
|
|
184
|
func AllowCors() func(ctx *context.Context) {
|
184
|
func AllowCors() func(ctx *context.Context) {
|
185
|
return func(ctx *context.Context) {
|
185
|
return func(ctx *context.Context) {
|
|
|
186
|
+ log.Debug(ctx.Request.Method, ctx.Request.RequestURI)
|
186
|
ctx.Output.Header("Access-Control-Allow-Methods", "OPTIONS,DELETE,POST,GET,PUT,PATCH")
|
187
|
ctx.Output.Header("Access-Control-Allow-Methods", "OPTIONS,DELETE,POST,GET,PUT,PATCH")
|
187
|
//ctx.Output.Header("Access-Control-Max-Age", "3600")
|
188
|
//ctx.Output.Header("Access-Control-Max-Age", "3600")
|
188
|
ctx.Output.Header("Access-Control-Allow-Headers", "*")
|
189
|
ctx.Output.Header("Access-Control-Allow-Headers", "*")
|
189
|
ctx.Output.Header("Access-Control-Allow-Credentials", "true")
|
190
|
ctx.Output.Header("Access-Control-Allow-Credentials", "true")
|
190
|
ctx.Output.Header("Access-Control-Allow-Origin", "*") //origin
|
191
|
ctx.Output.Header("Access-Control-Allow-Origin", "*") //origin
|
191
|
- ctx.Output.Header("Access-Control-Allow-Private-Network","true")
|
192
|
+ ctx.Output.Header("Access-Control-Allow-Private-Network", "true")
|
192
|
if ctx.Input.Method() == http.MethodOptions {
|
193
|
if ctx.Input.Method() == http.MethodOptions {
|
193
|
// options请求,返回200
|
194
|
// options请求,返回200
|
194
|
ctx.Output.SetStatus(http.StatusOK)
|
195
|
ctx.Output.SetStatus(http.StatusOK)
|