Merge branch 'test-gencode' into dev
正在显示
12 个修改的文件
包含
286 行增加
和
17 行删除
| @@ -5,6 +5,7 @@ go 1.14 | @@ -5,6 +5,7 @@ go 1.14 | ||
| 5 | require ( | 5 | require ( |
| 6 | github.com/astaxie/beego v1.12.1 | 6 | github.com/astaxie/beego v1.12.1 |
| 7 | github.com/dgrijalva/jwt-go v3.2.0+incompatible | 7 | github.com/dgrijalva/jwt-go v3.2.0+incompatible |
| 8 | + github.com/gin-gonic/gin v1.4.0 | ||
| 8 | github.com/go-pg/pg/v10 v10.0.0-beta.2 | 9 | github.com/go-pg/pg/v10 v10.0.0-beta.2 |
| 9 | github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 | 10 | github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 |
| 10 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect | 11 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect |
| @@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
| 7 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" | 7 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" |
| 8 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis" | 8 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis" |
| 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
| 10 | + //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr" | ||
| 10 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr" | 11 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr" |
| 11 | ) | 12 | ) |
| 12 | 13 | ||
| @@ -16,5 +17,6 @@ func main() { | @@ -16,5 +17,6 @@ func main() { | ||
| 16 | }() | 17 | }() |
| 17 | log.Info("app start!") | 18 | log.Info("app start!") |
| 18 | log.Info(constant.POSTGRESQL_DB_NAME) | 19 | log.Info(constant.POSTGRESQL_DB_NAME) |
| 20 | + //ginsvr.Run() | ||
| 19 | beego.Run() | 21 | beego.Run() |
| 20 | } | 22 | } |
| @@ -66,7 +66,7 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -66,7 +66,7 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
| 66 | err = protocol.NewCustomMessage(1, "登录方式不支持!") | 66 | err = protocol.NewCustomMessage(1, "登录方式不支持!") |
| 67 | break | 67 | break |
| 68 | } | 68 | } |
| 69 | - rsp.AuthCode, _ = utils.GenerateToken(partnerInfo.Id, protocol.AuthCodeExpire*time.Second) | 69 | + rsp.AuthCode, _ = utils.GenerateToken(partnerInfo.Id, request.Phone, protocol.AuthCodeExpire*time.Second) |
| 70 | 70 | ||
| 71 | if err = InitOrUpdateUserIMInfo(partnerInfo, transactionContext); err != nil { | 71 | if err = InitOrUpdateUserIMInfo(partnerInfo, transactionContext); err != nil { |
| 72 | log.Error(err) | 72 | log.Error(err) |
| @@ -105,8 +105,8 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke | @@ -105,8 +105,8 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke | ||
| 105 | err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt authCode (%v) valid", request.AuthCode)) | 105 | err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt authCode (%v) valid", request.AuthCode)) |
| 106 | return | 106 | return |
| 107 | } | 107 | } |
| 108 | - rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, protocol.TokenExpire*time.Second) | ||
| 109 | - rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, protocol.RefreshTokenExipre*time.Second) | 108 | + rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, claim.Phone, protocol.TokenExpire*time.Second) |
| 109 | + rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, claim.Phone, protocol.RefreshTokenExipre*time.Second) | ||
| 110 | rsp.ExpiresIn = protocol.TokenExpire | 110 | rsp.ExpiresIn = protocol.TokenExpire |
| 111 | 111 | ||
| 112 | //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId), | 112 | //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId), |
| @@ -121,8 +121,22 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke | @@ -121,8 +121,22 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke | ||
| 121 | 121 | ||
| 122 | func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) { | 122 | func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) { |
| 123 | var ( | 123 | var ( |
| 124 | - claim *utils.UserTokenClaims | 124 | + claim *utils.UserTokenClaims |
| 125 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 126 | + PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | ||
| 127 | + PartnerSubAccountRepository, _ = factory.CreatePartnerSubAccountRepository(transactionContext) | ||
| 128 | + | ||
| 129 | + partnerInfo *domain.PartnerInfo | ||
| 130 | + partnerSubAccount *domain.PartnerSubAccount | ||
| 125 | ) | 131 | ) |
| 132 | + | ||
| 133 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 134 | + return nil, err | ||
| 135 | + } | ||
| 136 | + defer func() { | ||
| 137 | + transactionContext.RollbackTransaction() | ||
| 138 | + }() | ||
| 139 | + | ||
| 126 | rsp = &protocol.RefreshTokenResponse{} | 140 | rsp = &protocol.RefreshTokenResponse{} |
| 127 | if claim, err = utils.ParseJWTToken(request.RefreshToken); err != nil { | 141 | if claim, err = utils.ParseJWTToken(request.RefreshToken); err != nil { |
| 128 | err = protocol.NewErrWithMessage(4140, err) | 142 | err = protocol.NewErrWithMessage(4140, err) |
| @@ -132,14 +146,27 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | @@ -132,14 +146,27 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | ||
| 132 | err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt refrshToken (%v) valid", request.RefreshToken)) | 146 | err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt refrshToken (%v) valid", request.RefreshToken)) |
| 133 | return | 147 | return |
| 134 | } | 148 | } |
| 149 | + | ||
| 150 | + //验证用户有效 | ||
| 151 | + var e error | ||
| 152 | + if partnerSubAccount, e = PartnerSubAccountRepository.FindOne(map[string]interface{}{"account": claim.Phone}); e == nil { | ||
| 153 | + partnerInfo, e = PartnerInfoService.FindOne(map[string]interface{}{"id": partnerSubAccount.PartnerId}) | ||
| 154 | + } else { | ||
| 155 | + partnerInfo, e = PartnerInfoService.FindOne(map[string]interface{}{"account": claim.Phone}) | ||
| 156 | + } | ||
| 157 | + if e != nil || partnerInfo == nil || !partnerInfo.IsEnable() || partnerInfo.Id != claim.UserId { | ||
| 158 | + err = protocol.NewErrWithMessage(4140) //账号禁用 | ||
| 159 | + return | ||
| 160 | + } | ||
| 161 | + | ||
| 135 | //oldAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId)) | 162 | //oldAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId)) |
| 136 | //if err = oldAuth.Check(userAuth.NewOptions(userAuth.WithRefreshToken(request.RefreshToken))); err != nil { | 163 | //if err = oldAuth.Check(userAuth.NewOptions(userAuth.WithRefreshToken(request.RefreshToken))); err != nil { |
| 137 | // log.Error(err) | 164 | // log.Error(err) |
| 138 | // err = protocol.NewErrWithMessage(4140, err) | 165 | // err = protocol.NewErrWithMessage(4140, err) |
| 139 | // return | 166 | // return |
| 140 | //} | 167 | //} |
| 141 | - rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, protocol.TokenExpire*time.Second) | ||
| 142 | - rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, protocol.RefreshTokenExipre*time.Second) | 168 | + rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, claim.Phone, protocol.TokenExpire*time.Second) |
| 169 | + rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, claim.Phone, protocol.RefreshTokenExipre*time.Second) | ||
| 143 | rsp.ExpiresIn = protocol.TokenExpire | 170 | rsp.ExpiresIn = protocol.TokenExpire |
| 144 | 171 | ||
| 145 | //newAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId), | 172 | //newAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId), |
| @@ -149,6 +176,7 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | @@ -149,6 +176,7 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | ||
| 149 | // log.Error(err) | 176 | // log.Error(err) |
| 150 | // return | 177 | // return |
| 151 | //} | 178 | //} |
| 179 | + err = transactionContext.CommitTransaction() | ||
| 152 | return | 180 | return |
| 153 | } | 181 | } |
| 154 | 182 |
| @@ -14,8 +14,6 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis | @@ -14,8 +14,6 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis | ||
| 14 | var ( | 14 | var ( |
| 15 | transactionContext, _ = factory.CreateTransactionContext(nil) | 15 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 16 | OrderBaseResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext) | 16 | OrderBaseResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext) |
| 17 | - //beginTime = time.Unix(request.StartTime/1000, 0) | ||
| 18 | - //endTime = time.Unix(request.EndTime/1000, 0) | ||
| 19 | ) | 17 | ) |
| 20 | if err = transactionContext.StartTransaction(); err != nil { | 18 | if err = transactionContext.StartTransaction(); err != nil { |
| 21 | return nil, err | 19 | return nil, err |
| @@ -2,11 +2,11 @@ package constant | @@ -2,11 +2,11 @@ package constant | ||
| 2 | 2 | ||
| 3 | import "os" | 3 | import "os" |
| 4 | 4 | ||
| 5 | -var POSTGRESQL_DB_NAME = "partner_dev" //partner | ||
| 6 | -var POSTGRESQL_USER = "postgres" // | ||
| 7 | -var POSTGRESQL_PASSWORD = "postgres_15432" //pgsql@123 | ||
| 8 | -var POSTGRESQL_HOST = "101.37.68.23" //127.0.0.1 | ||
| 9 | -var POSTGRESQL_PORT = "15432" //5432 | 5 | +var POSTGRESQL_DB_NAME = "partner_dev" //partner |
| 6 | +var POSTGRESQL_USER = "postgres" // | ||
| 7 | +var POSTGRESQL_PASSWORD = "eagle1010" //pgsql@123 | ||
| 8 | +var POSTGRESQL_HOST = "114.55.200.59" //127.0.0.1 | ||
| 9 | +var POSTGRESQL_PORT = "31543" //5432 | ||
| 10 | var DISABLE_CREATE_TABLE = false | 10 | var DISABLE_CREATE_TABLE = false |
| 11 | var DISABLE_SQL_GENERATE_PRINT = false | 11 | var DISABLE_SQL_GENERATE_PRINT = false |
| 12 | 12 |
| @@ -6,7 +6,8 @@ import ( | @@ -6,7 +6,8 @@ import ( | ||
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | type UserTokenClaims struct { | 8 | type UserTokenClaims struct { |
| 9 | - UserId int64 `json:"userId"` | 9 | + UserId int64 `json:"userId"` |
| 10 | + Phone string `json:"phone"` | ||
| 10 | jwt.StandardClaims | 11 | jwt.StandardClaims |
| 11 | } | 12 | } |
| 12 | 13 | ||
| @@ -33,11 +34,12 @@ func ParseJWTToken(token string) (*UserTokenClaims, error) { | @@ -33,11 +34,12 @@ func ParseJWTToken(token string) (*UserTokenClaims, error) { | ||
| 33 | //@uid 用户变化 | 34 | //@uid 用户变化 |
| 34 | //@password 密码 | 35 | //@password 密码 |
| 35 | //@expire 过期时长 | 36 | //@expire 过期时长 |
| 36 | -func GenerateToken(uid int64, expire time.Duration) (string, error) { | 37 | +func GenerateToken(uid int64, phone string, expire time.Duration) (string, error) { |
| 37 | now := time.Now() | 38 | now := time.Now() |
| 38 | expireTime := now.Add(expire) | 39 | expireTime := now.Add(expire) |
| 39 | claims := UserTokenClaims{ | 40 | claims := UserTokenClaims{ |
| 40 | UserId: uid, | 41 | UserId: uid, |
| 42 | + Phone: phone, | ||
| 41 | StandardClaims: jwt.StandardClaims{ | 43 | StandardClaims: jwt.StandardClaims{ |
| 42 | ExpiresAt: expireTime.Unix(), | 44 | ExpiresAt: expireTime.Unix(), |
| 43 | Issuer: "jwt", | 45 | Issuer: "jwt", |
pkg/port/ginsvr/controllers/base.go
0 → 100644
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/astaxie/beego/validation" | ||
| 5 | + "github.com/gin-gonic/gin" | ||
| 6 | + "github.com/tiptok/gocomm/pkg/mygin" | ||
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 8 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
| 9 | + "strconv" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type BaseController struct { | ||
| 13 | + mygin.BaseController | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (this *BaseController) Resp(c *gin.Context, httpCode int, rsp *protocol.ResponseMessage) { | ||
| 17 | + c.Set("outputData", rsp) | ||
| 18 | + c.JSON(httpCode, rsp) | ||
| 19 | + //c.Abort() | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func (controller *BaseController) Valid(obj interface{}) (result bool, msg *protocol.ResponseMessage) { | ||
| 23 | + /*校验*/ | ||
| 24 | + var err error | ||
| 25 | + valid := validation.Validation{} | ||
| 26 | + result, err = valid.Valid(obj) | ||
| 27 | + if err != nil { | ||
| 28 | + } | ||
| 29 | + if !result { | ||
| 30 | + msg = protocol.BadRequestParam(2) | ||
| 31 | + return | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + return | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +//获取请求头信息 | ||
| 38 | +func (this *BaseController) GetRequestHeader(c *gin.Context) *protocol.RequestHeader { | ||
| 39 | + h := &protocol.RequestHeader{} | ||
| 40 | + | ||
| 41 | + h.AccessToken = c.Query("x-mmm-accesstoken") | ||
| 42 | + h.AppProject = c.Query("x-mmm-appproject") | ||
| 43 | + h.DeviceType, _ = strconv.Atoi(c.Query("x-mmm-devicetype")) | ||
| 44 | + h.Sign = c.Query("x-mmm-sign") | ||
| 45 | + h.Uuid = c.Query("x-mmm-uuid") | ||
| 46 | + h.TimeStamp = c.Query("x-mmm-timestamp") | ||
| 47 | + h.Version = c.Query("x-mmm-version") | ||
| 48 | + h.UserId, _ = strconv.ParseInt(c.Query("x-mmm-id"), 10, 64) | ||
| 49 | + | ||
| 50 | + if len(h.AccessToken) > 0 { | ||
| 51 | + if claim, err := utils.ParseJWTToken(h.AccessToken); err == nil { | ||
| 52 | + h.UserId = claim.UserId | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + return h | ||
| 56 | +} |
pkg/port/ginsvr/controllers/order.go
0 → 100644
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/gin-gonic/gin" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/order" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
| 8 | + "net/http" | ||
| 9 | + "time" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type OrderController struct { | ||
| 13 | + BaseController | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +//OrderStatistics 订单统计 | ||
| 17 | +// @router /statistics [post] | ||
| 18 | +func (this *OrderController) Statistics(c *gin.Context) { | ||
| 19 | + var msg *protocol.ResponseMessage | ||
| 20 | + defer func() { | ||
| 21 | + this.Resp(c, http.StatusOK, msg) | ||
| 22 | + }() | ||
| 23 | + var request *protocol.OrderStatisticsRequest | ||
| 24 | + if err := c.ShouldBind(&request); err != nil { | ||
| 25 | + msg = protocol.BadRequestParam(1) | ||
| 26 | + return | ||
| 27 | + } | ||
| 28 | + if b, m := this.Valid(request); !b { | ||
| 29 | + msg = m | ||
| 30 | + return | ||
| 31 | + } | ||
| 32 | + header := this.GetRequestHeader(c) | ||
| 33 | + msg = protocol.NewReturnResponse(order.Statistics(header, request)) | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +//OrderDetail 订单详情 | ||
| 37 | +// @router /orderDetail [post] | ||
| 38 | +func (this *OrderController) OrderDetail(c *gin.Context) { | ||
| 39 | + var msg *protocol.ResponseMessage | ||
| 40 | + defer func() { | ||
| 41 | + this.Resp(c, http.StatusOK, msg) | ||
| 42 | + }() | ||
| 43 | + var request *protocol.OrderDetailRequest | ||
| 44 | + if err := c.ShouldBind(&request); err != nil { | ||
| 45 | + msg = protocol.BadRequestParam(1) | ||
| 46 | + return | ||
| 47 | + } | ||
| 48 | + if b, m := this.Valid(request); !b { | ||
| 49 | + msg = m | ||
| 50 | + return | ||
| 51 | + } | ||
| 52 | + header := this.GetRequestHeader(c) | ||
| 53 | + msg = protocol.NewReturnResponse(order.Detail(header, request)) | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +//OrderList | ||
| 57 | +func (this *OrderController) OrderList(c *gin.Context) { | ||
| 58 | + var msg *protocol.ResponseMessage | ||
| 59 | + defer func() { | ||
| 60 | + this.Resp(c, http.StatusOK, msg) | ||
| 61 | + }() | ||
| 62 | + var request *protocol.OrderListRequest | ||
| 63 | + if err := c.ShouldBind(&request); err != nil { | ||
| 64 | + msg = protocol.BadRequestParam(1) | ||
| 65 | + return | ||
| 66 | + } | ||
| 67 | + if b, m := this.Valid(request); !b { | ||
| 68 | + msg = m | ||
| 69 | + return | ||
| 70 | + } | ||
| 71 | + request.OrderType = domain.OrderReal | ||
| 72 | + header := this.GetRequestHeader(c) | ||
| 73 | + msg = protocol.NewReturnResponse(order.List(header, request)) | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +//OrderList | ||
| 77 | +func (this *OrderController) Intentions(c *gin.Context) { | ||
| 78 | + var msg *protocol.ResponseMessage | ||
| 79 | + defer func() { | ||
| 80 | + this.Resp(c, http.StatusOK, msg) | ||
| 81 | + }() | ||
| 82 | + var request *protocol.OrderListRequest | ||
| 83 | + if err := c.ShouldBind(&request); err != nil { | ||
| 84 | + msg = protocol.BadRequestParam(1) | ||
| 85 | + return | ||
| 86 | + } | ||
| 87 | + if b, m := this.Valid(request); !b { | ||
| 88 | + msg = m | ||
| 89 | + return | ||
| 90 | + } | ||
| 91 | + request.EndTime = time.Now().Unix() * 1000 | ||
| 92 | + request.OrderType = domain.OrderIntention | ||
| 93 | + header := this.GetRequestHeader(c) | ||
| 94 | + msg = protocol.NewReturnResponse(order.List(header, request)) | ||
| 95 | +} |
pkg/port/ginsvr/gin.go
0 → 100644
pkg/port/ginsvr/middleware/log.go
0 → 100644
| 1 | +package middleware | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "fmt" | ||
| 6 | + "github.com/gin-gonic/gin" | ||
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | ||
| 8 | + "io/ioutil" | ||
| 9 | + "net/http" | ||
| 10 | + "time" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +func CreateRequstLogFilter() gin.HandlerFunc { | ||
| 14 | + return func(ctx *gin.Context) { | ||
| 15 | + requestId := fmt.Sprintf("%v.%v", ctx.Request.Method, ctx.Request.RequestURI) | ||
| 16 | + ctx.Set("requestId", requestId) | ||
| 17 | + var body string = "{}" | ||
| 18 | + if _, ok := ctx.Get("requestBody"); ok { | ||
| 19 | + data, _ := ctx.Get("requestBody") | ||
| 20 | + body = string(data.([]byte)) | ||
| 21 | + } | ||
| 22 | + start := time.Now() | ||
| 23 | + ctx.Next() | ||
| 24 | + end := time.Now() | ||
| 25 | + latency := end.Sub(start) | ||
| 26 | + | ||
| 27 | + v, _ := ctx.Get("outputData") | ||
| 28 | + rspBody, _ := json.Marshal(v) | ||
| 29 | + if len(rspBody) > 500 { | ||
| 30 | + rspBody = rspBody[:500] | ||
| 31 | + } | ||
| 32 | + log.Debug(fmt.Sprintf("====>Recv User:%v | %v | %s | %v | \nAuth=%v \nReqBody:%s \nRspBody:%v", ctx.Query("UserId"), ctx.ClientIP(), requestId, latency, ctx.Query("x-mmm-accesstoken"), body, string(rspBody))) | ||
| 33 | + } | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +func CreateResponseLogFilter() func(ctx *gin.Context) { | ||
| 37 | + return func(ctx *gin.Context) { | ||
| 38 | + requestId, _ := ctx.Get("requestId") | ||
| 39 | + v, _ := ctx.Get("outputData") | ||
| 40 | + body, _ := json.Marshal(v) | ||
| 41 | + if len(body) > 1000 { | ||
| 42 | + body = body[:1000] | ||
| 43 | + } | ||
| 44 | + log.Debug(fmt.Sprintf("<====Send RequestId:%v BodyData:%s", requestId, body)) | ||
| 45 | + } | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +func CreateRequestBodyFilter() func(ctx *gin.Context) { | ||
| 49 | + return func(ctx *gin.Context) { | ||
| 50 | + if ctx.Request.Method == http.MethodPost || ctx.Request.Method == http.MethodPut { | ||
| 51 | + body, _ := ioutil.ReadAll(ctx.Request.Body) | ||
| 52 | + if len(body) == 0 { | ||
| 53 | + body = []byte("{}") | ||
| 54 | + } | ||
| 55 | + ctx.Set("requestBody", body) | ||
| 56 | + ctx.Request.Body.Close() | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | +} |
pkg/port/ginsvr/routers/router.go
0 → 100644
| 1 | +package routers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/gin-gonic/gin/ginS" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr/controllers" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr/middleware" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +func init() { | ||
| 10 | + //ginS.Use(middleware.CreateRequestBodyFilter()) | ||
| 11 | + ginS.Use(middleware.CreateRequstLogFilter()) | ||
| 12 | + | ||
| 13 | + order := &controllers.OrderController{} | ||
| 14 | + ginS.POST("/order/statistics", order.Statistics) | ||
| 15 | + ginS.POST("/order/details", order.OrderDetail) | ||
| 16 | + ginS.POST("/order/list", order.OrderList) | ||
| 17 | + ginS.POST("/order/intentions", order.Intentions) | ||
| 18 | +} |
| @@ -5,9 +5,9 @@ const ( | @@ -5,9 +5,9 @@ const ( | ||
| 5 | LoginBySmsCode = "signInCaptcha" | 5 | LoginBySmsCode = "signInCaptcha" |
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | -const AuthCodeExpire = 60 * 15 | 8 | +const AuthCodeExpire = 60 * 15 //15分钟过期 |
| 9 | 9 | ||
| 10 | -const TokenExpire = 60 * 60 * 2 | 10 | +const TokenExpire = 60 * 60 * 2 //两个小时过期 |
| 11 | const RefreshTokenExipre = 3600 * 24 * 30 * 1 //刷新token 一个月过期 | 11 | const RefreshTokenExipre = 3600 * 24 * 30 * 1 //刷新token 一个月过期 |
| 12 | 12 | ||
| 13 | //const TokenExpire = 30 | 13 | //const TokenExpire = 30 |
-
请 注册 或 登录 后发表评论