|
@@ -8,6 +8,7 @@ import (
|
|
|
"app.yhyue.com/moapp/jyPoints/rpc/internal/svc"
|
|
|
"app.yhyue.com/moapp/jyPoints/service"
|
|
|
"context"
|
|
|
+ "encoding/json"
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
@@ -18,6 +19,7 @@ import (
|
|
|
"golang.org/x/time/rate"
|
|
|
"google.golang.org/grpc"
|
|
|
"log"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -37,6 +39,7 @@ func main() {
|
|
|
integral.RegisterIntegralServer(grpcServer, srv)
|
|
|
})
|
|
|
s.AddUnaryInterceptors(rateLimitInterceptor)
|
|
|
+ s.AddUnaryInterceptors()
|
|
|
defer s.Stop()
|
|
|
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
|
|
b := cron.New()
|
|
@@ -60,7 +63,81 @@ func init() {
|
|
|
func rateLimitInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
|
|
fmt.Println("拦截器")
|
|
|
log.Println("方法名:",info.FullMethod," 参数:",req)
|
|
|
- return handler(ctx, req)
|
|
|
+ resp, err = handler(ctx, req)
|
|
|
+ fmt.Println("返回值",resp,err)
|
|
|
+ orm := entity.Engine.NewSession()
|
|
|
+/* reqData := req.(map[string]interface{})
|
|
|
+ appId:=reqData["AppId"]*/
|
|
|
+ var dat map[string]interface{}
|
|
|
+ jsonStr := Strval(req)
|
|
|
+ if err := json.Unmarshal([]byte(jsonStr), &dat); err == nil {
|
|
|
+ fmt.Println(dat)
|
|
|
+ }
|
|
|
+ appId:=dat["appId"]
|
|
|
+ eqspStr := Strval(resp)
|
|
|
+ if(len(eqspStr)>300){
|
|
|
+ eqspStr=eqspStr[0:300]
|
|
|
+ }
|
|
|
+ var sqlerr error
|
|
|
+ _,sqlerr = orm.Exec("INSERT INTO `interface_log`(`interName`, `calleeId`, `appId`, `inParameter`, `reTurnInfo`, `node`, `summary`,timestamp) VALUES (?,?,?,?,?,?,?,now())",info.FullMethod,c.CalleeId,appId,jsonStr,eqspStr,c.Node,"")
|
|
|
+ if sqlerr != nil {
|
|
|
+ log.Print("日志存储失败", sqlerr)
|
|
|
+ }
|
|
|
+ return resp,err
|
|
|
+}
|
|
|
+func Strval(value interface{}) string {
|
|
|
+ var key string
|
|
|
+ if value == nil {
|
|
|
+ return key
|
|
|
+ }
|
|
|
+
|
|
|
+ switch value.(type) {
|
|
|
+ case float64:
|
|
|
+ ft := value.(float64)
|
|
|
+ key = strconv.FormatFloat(ft, 'f', -1, 64)
|
|
|
+ case float32:
|
|
|
+ ft := value.(float32)
|
|
|
+ key = strconv.FormatFloat(float64(ft), 'f', -1, 64)
|
|
|
+ case int:
|
|
|
+ it := value.(int)
|
|
|
+ key = strconv.Itoa(it)
|
|
|
+ case uint:
|
|
|
+ it := value.(uint)
|
|
|
+ key = strconv.Itoa(int(it))
|
|
|
+ case int8:
|
|
|
+ it := value.(int8)
|
|
|
+ key = strconv.Itoa(int(it))
|
|
|
+ case uint8:
|
|
|
+ it := value.(uint8)
|
|
|
+ key = strconv.Itoa(int(it))
|
|
|
+ case int16:
|
|
|
+ it := value.(int16)
|
|
|
+ key = strconv.Itoa(int(it))
|
|
|
+ case uint16:
|
|
|
+ it := value.(uint16)
|
|
|
+ key = strconv.Itoa(int(it))
|
|
|
+ case int32:
|
|
|
+ it := value.(int32)
|
|
|
+ key = strconv.Itoa(int(it))
|
|
|
+ case uint32:
|
|
|
+ it := value.(uint32)
|
|
|
+ key = strconv.Itoa(int(it))
|
|
|
+ case int64:
|
|
|
+ it := value.(int64)
|
|
|
+ key = strconv.FormatInt(it, 10)
|
|
|
+ case uint64:
|
|
|
+ it := value.(uint64)
|
|
|
+ key = strconv.FormatUint(it, 10)
|
|
|
+ case string:
|
|
|
+ key = value.(string)
|
|
|
+ case []byte:
|
|
|
+ key = string(value.([]byte))
|
|
|
+ default:
|
|
|
+ newValue, _ := json.Marshal(value)
|
|
|
+ key = string(newValue)
|
|
|
+ }
|
|
|
+
|
|
|
+ return key
|
|
|
}
|
|
|
|
|
|
func timeDask() {
|