root.go 502 B

1234567891011121314151617181920212223242526
  1. package routers
  2. import (
  3. "tmr-watch/http/handle/group"
  4. "tmr-watch/middleware"
  5. "github.com/gin-contrib/gzip"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func Root(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
  9. return func(s *gin.Engine) {
  10. for _, opt := range opts {
  11. opt(s)
  12. }
  13. s.NoRoute(group.Handle404)
  14. // common middleware
  15. s.Use(
  16. middleware.CORS(),
  17. gzip.Gzip(gzip.DefaultCompression),
  18. middleware.Pagination(),
  19. middleware.GinLogger(),
  20. middleware.GinRecovery(true),
  21. )
  22. }
  23. }