1
|
package controllers
|
1
|
package controllers
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+ "strconv"
|
|
|
6
|
+ "strings"
|
4
|
"crypto/sha256"
|
7
|
"crypto/sha256"
|
5
|
"encoding/hex"
|
8
|
"encoding/hex"
|
6
|
- "fmt"
|
|
|
7
|
- "github.com/astaxie/beego"
|
|
|
8
|
- "github.com/astaxie/beego/context"
|
|
|
9
|
- "github.com/astaxie/beego/validation"
|
9
|
+
|
10
|
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
|
10
|
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
|
11
|
"gitlab.fjmaimaimai.com/mmm-go/ability/services/auth"
|
11
|
"gitlab.fjmaimaimai.com/mmm-go/ability/services/auth"
|
12
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
12
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
13
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
13
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
14
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
|
14
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
|
15
|
- "strconv"
|
|
|
16
|
|
15
|
|
17
|
- //"strconv"
|
|
|
18
|
- "strings"
|
16
|
+ "github.com/astaxie/beego"
|
|
|
17
|
+ "github.com/astaxie/beego/context"
|
|
|
18
|
+ "github.com/astaxie/beego/validation"
|
19
|
)
|
19
|
)
|
20
|
|
20
|
|
21
|
type BaseController struct {
|
21
|
type BaseController struct {
|
|
@@ -41,7 +41,6 @@ func (this *BaseController)Valid(obj interface{})(result bool ,msg *mybeego.Mess |
|
@@ -41,7 +41,6 @@ func (this *BaseController)Valid(obj interface{})(result bool ,msg *mybeego.Mess |
41
|
}
|
41
|
}
|
42
|
return
|
42
|
return
|
43
|
}
|
43
|
}
|
44
|
-
|
|
|
45
|
//GenMessage genarate a response message
|
44
|
//GenMessage genarate a response message
|
46
|
func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message{
|
45
|
func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message{
|
47
|
var msg *mybeego.Message
|
46
|
var msg *mybeego.Message
|
|
@@ -50,7 +49,7 @@ func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message |
|
@@ -50,7 +49,7 @@ func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message |
50
|
msg.Data = rsp
|
49
|
msg.Data = rsp
|
51
|
return msg
|
50
|
return msg
|
52
|
}
|
51
|
}
|
53
|
- log.Error(err)
|
52
|
+ //log.Error(err)
|
54
|
if e,ok :=err.(common.Error);ok{
|
53
|
if e,ok :=err.(common.Error);ok{
|
55
|
msg = mybeego.NewMessage(e.Code)
|
54
|
msg = mybeego.NewMessage(e.Code)
|
56
|
msg.Data = rsp
|
55
|
msg.Data = rsp
|
|
@@ -59,7 +58,7 @@ func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message |
|
@@ -59,7 +58,7 @@ func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message |
59
|
msg = mybeego.NewMessage(1)
|
58
|
msg = mybeego.NewMessage(1)
|
60
|
return msg
|
59
|
return msg
|
61
|
}
|
60
|
}
|
62
|
-
|
61
|
+//获取请求头信息
|
63
|
func GetRequestHeader(ctx *context.Context)*protocol.RequestHeader{
|
62
|
func GetRequestHeader(ctx *context.Context)*protocol.RequestHeader{
|
64
|
h :=&protocol.RequestHeader{}
|
63
|
h :=&protocol.RequestHeader{}
|
65
|
h.AccessToken = ctx.Input.Header("x-mmm-accesstoken")
|
64
|
h.AccessToken = ctx.Input.Header("x-mmm-accesstoken")
|
|
@@ -72,6 +71,7 @@ func GetRequestHeader(ctx *context.Context)*protocol.RequestHeader{ |
|
@@ -72,6 +71,7 @@ func GetRequestHeader(ctx *context.Context)*protocol.RequestHeader{ |
72
|
return h
|
71
|
return h
|
73
|
}
|
72
|
}
|
74
|
|
73
|
|
|
|
74
|
+//过滤器
|
75
|
func FilterComm(ctx *context.Context){
|
75
|
func FilterComm(ctx *context.Context){
|
76
|
if strings.HasSuffix(ctx.Request.RequestURI,"login"){
|
76
|
if strings.HasSuffix(ctx.Request.RequestURI,"login"){
|
77
|
return
|
77
|
return
|