main.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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) // 云控展示线上评分
  45. examPrefix.POST("/page", handler.Page) // 分页查询
  46. examPrefix.POST("/report", handler.Report) // pdf下载
  47. examPrefix.POST("/offline", handler.Offline) // 录入线下成绩
  48. }
  49. }
  50. {
  51. monitorPrefix := router.Group("/web_server/monitor") // todo web_server会改成score_server,后续修改
  52. {
  53. monitorPrefix.POST("/insert", handler.SaveDeviceMonitor)
  54. }
  55. }
  56. {
  57. monitorPrefix := router.Group("/web_server/collect_limit") // todo web_server会改成score_server,后续修改
  58. {
  59. monitorPrefix.POST("/can_collect", handler.TriggerCollect)
  60. monitorPrefix.POST("/can_collect_plus", handler.CanCollectPlus)
  61. }
  62. }
  63. // 端口
  64. err := router.Run(":" + infra.ApplicationYaml.Web.Port)
  65. if err != nil {
  66. c_log.GlobalLogger.Error("程序崩溃,监听端口 "+infra.ApplicationYaml.Web.Port+" 失败:", err)
  67. os.Exit(-1)
  68. }
  69. }