12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package main
- import (
- "app.yhyue.com/moapp/jyResourcesCenter/entity"
- "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/config"
- "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/server"
- "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/svc"
- "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
- "app.yhyue.com/moapp/jyResourcesCenter/service"
- "flag"
- "fmt"
- _ "github.com/go-sql-driver/mysql"
- "github.com/go-xorm/xorm"
- "github.com/robfig/cron"
- "github.com/zeromicro/go-zero/core/conf"
- "github.com/zeromicro/go-zero/zrpc"
- "google.golang.org/grpc"
- "log"
- "strings"
- )
- var configFile = flag.String("f", "etc/resourcescenter.yaml", "the config file")
- var balanceService service.BalanceService
- func main() {
- flag.Parse()
- conf.MustLoad(*configFile, &config.ConfigJson)
- for key, value := range strings.Split(config.ConfigJson.ProductStr, ",") {
- config.ConfigJson.ProductMap[value] = key
- }
- ctx := svc.NewServiceContext(config.ConfigJson)
- srv := server.NewResourcesCenterServer(ctx)
- s := zrpc.MustNewServer(config.ConfigJson.RpcServerConf, func(grpcServer *grpc.Server) {
- resourcesCenter.RegisterResourcesCenterServer(grpcServer, srv)
- })
- defer s.Stop()
- fmt.Printf("Starting rpc server at %s...\n", config.ConfigJson.ListenOn)
- //timeDask()
- b := cron.New()
- b.AddFunc(config.ConfigJson.TimeSource, timeDask)
- b.Start()
- s.Start()
- }
- // 创建orm引擎
- func init() {
- conf.MustLoad(*configFile, &config.ConfigJson)
- var err error
- entity.Engine, err = xorm.NewEngine("mysql", config.ConfigJson.DataSource)
- entity.Engine.ShowSQL(true)
- if err != nil {
- log.Fatal("数据库连接失败:", err)
- }
- fmt.Println(config.ConfigJson.DataSource + "链接成功")
- }
- func timeDask() {
- balanceService.ExpireHandle()
- }
|