main.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import (
  3. "cicv-data-closedloop/amd64/score_server/handler"
  4. "cicv-data-closedloop/amd64/score_server/infra"
  5. "cicv-data-closedloop/common/config/c_db"
  6. "cicv-data-closedloop/common/config/c_log"
  7. "cicv-data-closedloop/common/gin/middleware"
  8. _ "embed"
  9. "github.com/gin-gonic/gin"
  10. _ "gopkg.in/yaml.v3"
  11. "os"
  12. )
  13. func init() {
  14. infra.InitApplication()
  15. c_log.InitLog(
  16. infra.ApplicationYaml.Log.Dir,
  17. infra.ApplicationYaml.Log.Prefix,
  18. )
  19. c_db.InitSqlxMysql(
  20. infra.ApplicationYaml.Mysql.Username,
  21. infra.ApplicationYaml.Mysql.Password,
  22. infra.ApplicationYaml.Mysql.Ip,
  23. infra.ApplicationYaml.Mysql.Port,
  24. infra.ApplicationYaml.Mysql.Dbname,
  25. infra.ApplicationYaml.Mysql.Charset,
  26. )
  27. c_db.InitSqlFilesMap(infra.ApplicationYaml.Mysql.SqlfileDir)
  28. }
  29. func main() {
  30. c_log.GlobalLogger.Info("配置文件为:", infra.ApplicationYaml)
  31. // 创建 gin 实例
  32. router := gin.Default()
  33. // 使用中间件
  34. router.Use(middleware.Cors()) // 解决cors
  35. router.Use(middleware.LogRequest()) // 请求日志打印
  36. router.Use(middleware.ValidateHeaders(infra.ApplicationYaml.Web.WhiteList, infra.ApplicationYaml.Web.Token)) // 全局请求头校验
  37. // 通过路由组设置全局前缀
  38. projectPrefix := router.Group(infra.ApplicationYaml.Web.RoutePrefix)
  39. {
  40. examPrefix := projectPrefix.Group("/exam")
  41. {
  42. examPrefix.POST("/tick", handler.Tick) // 考试开始
  43. go handler.ExamEndTicker() // 考试结束
  44. examPrefix.POST("/display", handler.Display) // 考试开始2
  45. //examPrefix.POST("/end", handler.End) // 考试结束2
  46. examPrefix.POST("/page", handler.Page) // 分页查询
  47. examPrefix.POST("/report", handler.Report) // pdf下载
  48. }
  49. }
  50. {
  51. monitorPrefix := router.Group("/web_server/monitor")
  52. {
  53. monitorPrefix.POST("/insert", handler.SaveDeviceMonitor)
  54. }
  55. }
  56. // 端口
  57. err := router.Run(":" + infra.ApplicationYaml.Web.Port)
  58. if err != nil {
  59. c_log.GlobalLogger.Error("程序崩溃,监听端口 "+infra.ApplicationYaml.Web.Port+" 失败:", err)
  60. os.Exit(-1)
  61. }
  62. }