|
@@ -24,35 +24,34 @@ import (
|
|
|
)
|
|
|
|
|
|
var configFile = flag.String("f", "etc/activity.yaml", "the config file")
|
|
|
-var c config.Config
|
|
|
+
|
|
|
func main() {
|
|
|
flag.Parse()
|
|
|
- conf.MustLoad(*configFile, &c)
|
|
|
- ctx := svc.NewServiceContext(c)
|
|
|
+ conf.MustLoad(*configFile, &config.ConfigJson)
|
|
|
+ ctx := svc.NewServiceContext(config.ConfigJson)
|
|
|
srv := server.NewActivityServer(ctx)
|
|
|
- s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
|
|
+ s := zrpc.MustNewServer(config.ConfigJson.RpcServerConf, func(grpcServer *grpc.Server) {
|
|
|
activity.RegisterActivityServer(grpcServer, srv)
|
|
|
})
|
|
|
+ s.AddUnaryInterceptors(rateLimitInterceptor)
|
|
|
defer s.Stop()
|
|
|
b := cron.New()
|
|
|
- b.AddFunc(c.TimeSource, timeDask)
|
|
|
+ b.AddFunc(config.ConfigJson.TimeSource, timeDask)
|
|
|
b.Start()
|
|
|
- timeDask()
|
|
|
- fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
|
|
+ fmt.Printf("Starting rpc server at %s...\n", config.ConfigJson.ListenOn)
|
|
|
s.Start()
|
|
|
}
|
|
|
//创建orm引擎
|
|
|
func init() {
|
|
|
var err error
|
|
|
- conf.MustLoad(*configFile, &c)
|
|
|
- entity.Engine, err = xorm.NewEngine("mysql", c.DataSource)
|
|
|
+ entity.Engine, err = xorm.NewEngine("mysql", config.ConfigJson.DataSource)
|
|
|
entity.Engine.ShowSQL(true)
|
|
|
if err != nil {
|
|
|
log.Fatal("数据库连接失败:", err)
|
|
|
}
|
|
|
- fmt.Println(c.DataSource+"链接成功")
|
|
|
+ fmt.Println(config.ConfigJson.DataSource+"链接成功")
|
|
|
|
|
|
- redisCfg := c.Redis
|
|
|
+ redisCfg := config.ConfigJson.Redis
|
|
|
if redisCfg.Addr != "" {
|
|
|
e := util.InitRedisPool(redisCfg.Modules, redisCfg.Addr, redisCfg.PoolMaxSize, redisCfg.PoolMaxIdle, redisCfg.IdleTimeout)
|
|
|
if e == nil {
|
|
@@ -82,7 +81,7 @@ func rateLimitInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
|
|
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,"")
|
|
|
+ _,sqlerr = orm.Exec("INSERT INTO `interface_log`(`interName`, `calleeId`, `appId`, `inParameter`, `reTurnInfo`, `node`, `summary`,timestamp) VALUES (?,?,?,?,?,?,?,now())",info.FullMethod,config.ConfigJson.CalleeId,appId,jsonStr,eqspStr,config.ConfigJson.Node,"")
|
|
|
if sqlerr != nil {
|
|
|
log.Print("日志存储失败", sqlerr)
|
|
|
}
|