...
|
...
|
@@ -30,7 +30,7 @@ func init() { |
|
|
|
|
|
var DefaultController *BaseController = &BaseController{}
|
|
|
|
|
|
//Valid valid struct
|
|
|
// Valid valid struct
|
|
|
func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.ResponseMessage) {
|
|
|
/*校验*/
|
|
|
var err error
|
...
|
...
|
@@ -66,7 +66,7 @@ func (this *BaseController) RespH5(msg *protocol.ResponseMessage) { |
|
|
this.ServeJSON()
|
|
|
}
|
|
|
|
|
|
//获取请求头信息
|
|
|
// 获取请求头信息
|
|
|
func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
|
|
|
h := &protocol.RequestHeader{}
|
|
|
h.AccessToken = ctx.Input.Header("x-mmm-accesstoken")
|
...
|
...
|
@@ -79,7 +79,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { |
|
|
return h
|
|
|
}
|
|
|
|
|
|
//过滤器
|
|
|
// 过滤器
|
|
|
func FilterComm(ctx *context.Context) {
|
|
|
if !CheckSign(ctx) {
|
|
|
return
|
...
|
...
|
@@ -87,7 +87,7 @@ func FilterComm(ctx *context.Context) { |
|
|
return
|
|
|
}
|
|
|
|
|
|
//检查签名
|
|
|
// 检查签名
|
|
|
func CheckSign(ctx *context.Context) (result bool) {
|
|
|
var (
|
|
|
h *protocol.RequestHeader
|
...
|
...
|
@@ -111,7 +111,7 @@ func CheckSign(ctx *context.Context) (result bool) { |
|
|
return
|
|
|
}
|
|
|
|
|
|
//AllowOption 允许跨域请求
|
|
|
// AllowOption 允许跨域请求
|
|
|
var AllowOption = func(ctx *context.Context) {
|
|
|
if ctx.Request.Method != "OPTIONS" {
|
|
|
return
|
...
|
...
|
@@ -130,7 +130,7 @@ var AllowOption = func(ctx *context.Context) { |
|
|
return
|
|
|
}
|
|
|
|
|
|
//LogRequestData Before Router
|
|
|
// LogRequestData Before Router
|
|
|
var LogRequestData = func(ctx *context.Context) {
|
|
|
log.Info("====>Recv Request:%s", ctx.Input.URI())
|
|
|
hmap := map[string]string{
|
...
|
...
|
@@ -183,12 +183,13 @@ func (this *BaseController) Finish() { |
|
|
|
|
|
func AllowCors() func(ctx *context.Context) {
|
|
|
return func(ctx *context.Context) {
|
|
|
log.Debug(ctx.Request.Method, ctx.Request.RequestURI)
|
|
|
ctx.Output.Header("Access-Control-Allow-Methods", "OPTIONS,DELETE,POST,GET,PUT,PATCH")
|
|
|
//ctx.Output.Header("Access-Control-Max-Age", "3600")
|
|
|
ctx.Output.Header("Access-Control-Allow-Headers", "*")
|
|
|
ctx.Output.Header("Access-Control-Allow-Credentials", "true")
|
|
|
ctx.Output.Header("Access-Control-Allow-Origin", "*") //origin
|
|
|
ctx.Output.Header("Access-Control-Allow-Private-Network","true")
|
|
|
ctx.Output.Header("Access-Control-Allow-Private-Network", "true")
|
|
|
if ctx.Input.Method() == http.MethodOptions {
|
|
|
// options请求,返回200
|
|
|
ctx.Output.SetStatus(http.StatusOK)
|
...
|
...
|
|