作者 yangfu

添加日志

@@ -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)
@@ -12,13 +12,12 @@ var nsV1 *beego.Namespace @@ -12,13 +12,12 @@ var nsV1 *beego.Namespace
12 12
13 func init() { 13 func init() {
14 nsV1 := beego.NewNamespace("v1", 14 nsV1 := beego.NewNamespace("v1",
15 - beego.NSNamespace("vod", beego.NSInclude(&v1.VodController{})),//, beego.NSBefore(controllers.AllowOption)  
16 - beego.NSNamespace("push", beego.NSInclude(&v1.PushController{})),//, beego.NSBefore(controllers.AllowOption)  
17 - beego.NSNamespace("sms", beego.NSInclude(&v1.SmsController{})),//, beego.NSBefore(controllers.AllowOption) 15 + beego.NSNamespace("vod", beego.NSInclude(&v1.VodController{})), //, beego.NSBefore(controllers.AllowOption)
  16 + beego.NSNamespace("push", beego.NSInclude(&v1.PushController{})), //, beego.NSBefore(controllers.AllowOption)
  17 + beego.NSNamespace("sms", beego.NSInclude(&v1.SmsController{})), //, beego.NSBefore(controllers.AllowOption)
18 ) 18 )
19 beego.SetStaticPath("/log", constant.LogFilePath) 19 beego.SetStaticPath("/log", constant.LogFilePath)
20 beego.Router("/v2/vod/createStsAuth", &v2.VodController{}, "Post:CreateStsAuth") 20 beego.Router("/v2/vod/createStsAuth", &v2.VodController{}, "Post:CreateStsAuth")
21 beego.AddNamespace(nsV1) 21 beego.AddNamespace(nsV1)
22 -  
23 beego.InsertFilter("/*", beego.BeforeRouter, controllers.AllowCors()) 22 beego.InsertFilter("/*", beego.BeforeRouter, controllers.AllowCors())
24 } 23 }