You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
957 B

  1. package main
  2. import (
  3. "github.com/gogf/gf/v2/frame/g"
  4. _ "link_homework/internal/packed"
  5. "github.com/gogf/gf/v2/os/gctx"
  6. _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
  7. "link_homework/internal/cmd"
  8. _ "link_homework/internal/logic"
  9. )
  10. func main() {
  11. ctx := gctx.GetInitCtx()
  12. //启动日志
  13. g.Log().Info(ctx, "服务启动中")
  14. //检查数据库链接
  15. // 检查默认数据库链接
  16. db := g.DB()
  17. if err := db.PingMaster(); err != nil {
  18. g.Log().Fatal(ctx, "默认数据库链接失败,请检查数据库链接配置")
  19. return
  20. }
  21. g.Log().Info(ctx, "默认数据库链接成功")
  22. // 检查 CMS 数据库链接
  23. cmsDb := g.DB("cms")
  24. if err := cmsDb.PingMaster(); err != nil {
  25. g.Log().Fatal(ctx, "CMS 数据库链接失败,请检查数据库链接配置")
  26. return
  27. }
  28. g.Log().Info(ctx, "CMS 数据库链接成功")
  29. //启动主命令逻辑
  30. cmd.Main.Run(ctx)
  31. //服务启动完成日志
  32. g.Log().Info(ctx, "服务启动完成")
  33. }