resourcesCenter.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jyResourcesCenter/entity"
  4. "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/config"
  5. "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/server"
  6. "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/svc"
  7. "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
  8. "app.yhyue.com/moapp/jyResourcesCenter/service"
  9. "flag"
  10. "fmt"
  11. _ "github.com/go-sql-driver/mysql"
  12. "github.com/go-xorm/xorm"
  13. "github.com/robfig/cron"
  14. "github.com/zeromicro/go-zero/core/conf"
  15. "github.com/zeromicro/go-zero/zrpc"
  16. "google.golang.org/grpc"
  17. "log"
  18. "strings"
  19. )
  20. var configFile = flag.String("f", "etc/resourcescenter.yaml", "the config file")
  21. var balanceService service.BalanceService
  22. func main() {
  23. flag.Parse()
  24. conf.MustLoad(*configFile, &config.ConfigJson)
  25. for key, value := range strings.Split(config.ConfigJson.ProductStr, ",") {
  26. config.ConfigJson.ProductMap[value] = key
  27. }
  28. ctx := svc.NewServiceContext(config.ConfigJson)
  29. srv := server.NewResourcesCenterServer(ctx)
  30. s := zrpc.MustNewServer(config.ConfigJson.RpcServerConf, func(grpcServer *grpc.Server) {
  31. resourcesCenter.RegisterResourcesCenterServer(grpcServer, srv)
  32. })
  33. defer s.Stop()
  34. fmt.Printf("Starting rpc server at %s...\n", config.ConfigJson.ListenOn)
  35. //timeDask()
  36. b := cron.New()
  37. b.AddFunc(config.ConfigJson.TimeSource, timeDask)
  38. b.Start()
  39. s.Start()
  40. }
  41. // 创建orm引擎
  42. func init() {
  43. conf.MustLoad(*configFile, &config.ConfigJson)
  44. var err error
  45. entity.Engine, err = xorm.NewEngine("mysql", config.ConfigJson.DataSource)
  46. entity.Engine.ShowSQL(true)
  47. if err != nil {
  48. log.Fatal("数据库连接失败:", err)
  49. }
  50. fmt.Println(config.ConfigJson.DataSource + "链接成功")
  51. }
  52. func timeDask() {
  53. balanceService.ExpireHandle()
  54. }