作者 yangfu

protocol

@@ -4,19 +4,24 @@ go 1.13 @@ -4,19 +4,24 @@ go 1.13
4 4
5 require ( 5 require (
6 github.com/astaxie/beego v1.10.0 6 github.com/astaxie/beego v1.10.0
  7 + github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
7 8
8 github.com/dgrijalva/jwt-go v3.2.0+incompatible 9 github.com/dgrijalva/jwt-go v3.2.0+incompatible
9 github.com/garyburd/redigo v1.6.0 10 github.com/garyburd/redigo v1.6.0
10 github.com/gin-gonic/gin v1.4.0 11 github.com/gin-gonic/gin v1.4.0
  12 + github.com/go-sql-driver/mysql v1.4.1 // indirect
11 github.com/google/go-cmp v0.2.0 13 github.com/google/go-cmp v0.2.0
12 github.com/gorilla/websocket v1.4.1 14 github.com/gorilla/websocket v1.4.1
  15 + github.com/lib/pq v1.2.0 // indirect
13 github.com/mattn/go-sqlite3 v1.11.0 // indirect 16 github.com/mattn/go-sqlite3 v1.11.0 // indirect
14 17
15 github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9 18 github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9
16 github.com/opentracing/opentracing-go v1.1.0 19 github.com/opentracing/opentracing-go v1.1.0
17 github.com/spf13/viper v1.4.0 20 github.com/spf13/viper v1.4.0
  21 + github.com/uber-go/atomic v1.4.0 // indirect
18 github.com/uber/jaeger-client-go v2.16.0+incompatible 22 github.com/uber/jaeger-client-go v2.16.0+incompatible
19 github.com/uber/jaeger-lib v2.0.0+incompatible 23 github.com/uber/jaeger-lib v2.0.0+incompatible
  24 + github.com/ugorji/go v1.1.7 // indirect
20 ) 25 )
21 26
22 replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43 27 replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43
@@ -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 {
@@ -6,6 +6,12 @@ import ( @@ -6,6 +6,12 @@ import (
6 "time" 6 "time"
7 ) 7 )
8 8
  9 +//type IMessage interface {
  10 +// MsgCode() int
  11 +// ErrMsg() string
  12 +// Data() interface{}
  13 +//}
  14 +
9 const ( 15 const (
10 TOTAL_SWITCH_ON int = 0 // 通行 16 TOTAL_SWITCH_ON int = 0 // 通行
11 TOTAL_SWITCH_OFF int = 1 // 关闭,系统停止受理 17 TOTAL_SWITCH_OFF int = 1 // 关闭,系统停止受理
@@ -13,9 +19,9 @@ const ( @@ -13,9 +19,9 @@ const (
13 ) 19 )
14 20
15 type Message struct { 21 type Message struct {
16 - Errno int `json:"errno"`  
17 - Errmsg string `json:"errmsg"`  
18 - SysTime int64 `json:"sys_time"` 22 + Errno int `json:"code"`
  23 + Errmsg string `json:"msg"`
  24 + SysTime int64 `json:"-"`
19 Data interface{} `json:"data"` 25 Data interface{} `json:"data"`
20 } 26 }
21 27
@@ -55,7 +61,7 @@ func init() { @@ -55,7 +61,7 @@ func init() {
55 ErrnoMsg[1] = "系统错误" 61 ErrnoMsg[1] = "系统错误"
56 ErrnoMsg[2] = "参数错误" 62 ErrnoMsg[2] = "参数错误"
57 ErrnoMsg[3] = "系统升级中" 63 ErrnoMsg[3] = "系统升级中"
58 - ErrnoMsg[4] = "您目前使用的版本过低,无法显示最新的相关内容,请使用响单单APP最新版本。" 64 + ErrnoMsg[4] = "您目前使用的版本过低,无法显示最新的相关内容,请使用最新版本。"
59 ErrnoMsg[5] = "描述包含敏感词,请重新编辑" 65 ErrnoMsg[5] = "描述包含敏感词,请重新编辑"
60 ErrnoMsg[6] ="重复提交,请稍后再试" 66 ErrnoMsg[6] ="重复提交,请稍后再试"
61 - }  
  67 +}