|
@@ -5,6 +5,7 @@ import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
"log"
|
|
"log"
|
|
|
|
+ "strings"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"app.yhyue.com/moapp/jyInfo/rpc/model"
|
|
"app.yhyue.com/moapp/jyInfo/rpc/model"
|
|
@@ -14,30 +15,35 @@ import (
|
|
|
|
|
|
//自定义拦截器 保存请求日志
|
|
//自定义拦截器 保存请求日志
|
|
func CustomInterceptors(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
|
func CustomInterceptors(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
|
- fmt.Println("拦截器")
|
|
|
|
- log.Println("方法名:", info.FullMethod, " 参数:", req)
|
|
|
|
|
|
+ fmt.Println("拦截器", info.FullMethod)
|
|
|
|
+ go func() {
|
|
|
|
+ if strings.Contains(info.FullMethod, "InfoFileUpload") {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ log.Println("方法名:", info.FullMethod, " 参数:", req)
|
|
|
|
|
|
- var dat map[string]interface{}
|
|
|
|
- reqByte, err := json.Marshal(req)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Println("---req----:", err)
|
|
|
|
- }
|
|
|
|
- if err := json.Unmarshal(reqByte, &dat); err == nil {
|
|
|
|
- fmt.Println(dat)
|
|
|
|
- }
|
|
|
|
- appId := dat["appId"]
|
|
|
|
- userId := dat["userId"]
|
|
|
|
- resp, err = handler(ctx, req)
|
|
|
|
- fmt.Println("返回值", resp, err, appId)
|
|
|
|
- respByte, err := json.Marshal(resp)
|
|
|
|
- if len(respByte) > 200 {
|
|
|
|
- respByte = respByte[:200]
|
|
|
|
- }
|
|
|
|
- if err != nil {
|
|
|
|
- log.Println("---resp----:", err)
|
|
|
|
- }
|
|
|
|
- if model.Mysql.InsertBySql("INSERT INTO `info_log`(`func`, `userId`, `appId`, `req`, `res`, `time`) VALUES (?,?,?,?,?,?)", info.FullMethod, userId, appId, string(reqByte), string(respByte), time.Now().Local()) < 1 {
|
|
|
|
- log.Println("保存日志异常:", userId)
|
|
|
|
- }
|
|
|
|
|
|
+ var dat map[string]interface{}
|
|
|
|
+ reqByte, err := json.Marshal(req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("---req----:", err)
|
|
|
|
+ }
|
|
|
|
+ if err := json.Unmarshal(reqByte, &dat); err == nil {
|
|
|
|
+ fmt.Println(dat)
|
|
|
|
+ }
|
|
|
|
+ appId := dat["appId"]
|
|
|
|
+ userId := dat["userId"]
|
|
|
|
+ resp, err = handler(ctx, req)
|
|
|
|
+ fmt.Println("返回值", resp, err, appId)
|
|
|
|
+ respByte, err := json.Marshal(resp)
|
|
|
|
+ if len(respByte) > 200 {
|
|
|
|
+ respByte = respByte[:200]
|
|
|
|
+ }
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("---resp----:", err)
|
|
|
|
+ }
|
|
|
|
+ if model.Mysql.InsertBySql("INSERT INTO `info_log`(`func`, `userId`, `appId`, `req`, `res`, `time`) VALUES (?,?,?,?,?,?)", info.FullMethod, userId, appId, string(reqByte), string(respByte), time.Now().Local()) < 1 {
|
|
|
|
+ log.Println("保存日志异常:", userId)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
return resp, err
|
|
return resp, err
|
|
}
|
|
}
|