main.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package main
  2. import (
  3. "cicv-data-closedloop/amd64/web_server/handler"
  4. "cicv-data-closedloop/amd64/web_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. examPrefix := projectPrefix.Group("/exam")
  40. examPrefix.POST("/tick", handler.Tick) // 考试开始
  41. go handler.ExamEndTicker() // 考试结束
  42. examPrefix.POST("/begin", handler.Begin) // 考试开始2
  43. examPrefix.POST("/end", handler.End) // 考试结束2
  44. examPrefix.POST("/page", handler.Page) // 分页查询
  45. examPrefix.POST("/report", handler.Report) // pdf下载
  46. monitorPrefix := projectPrefix.Group("/monitor")
  47. monitorPrefix.POST("/insert", handler.SaveDeviceMonitor)
  48. // 端口
  49. err := router.Run(":" + infra.ApplicationYaml.Web.Port)
  50. if err != nil {
  51. c_log.GlobalLogger.Error("程序崩溃,监听端口 "+infra.ApplicationYaml.Web.Port+" 失败:", err)
  52. os.Exit(-1)
  53. }
  54. }