need_init.go 394 B

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