need_init.go 480 B

12345678910111213141516171819202122
  1. package middleware
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // 处理跨域请求,支持options访问
  8. func NeedInit() gin.HandlerFunc {
  9. return func(c *gin.Context) {
  10. if global.GVA_DB == nil {
  11. response.OkWithDetailed(gin.H{
  12. "needInit": true,
  13. }, "前往初始化数据库", c)
  14. c.Abort()
  15. } else {
  16. c.Next()
  17. }
  18. // 处理请求
  19. }
  20. }