middleware.go 650 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * @desc:中间件处理
  3. * @company:云南奇讯科技有限公司
  4. * @Author: yixiaohu<yxh669@qq.com>
  5. * @Date: 2022/3/17 9:11
  6. */
  7. package service
  8. import "github.com/gogf/gf/v2/net/ghttp"
  9. type IMiddleware interface {
  10. MiddlewareCORS(r *ghttp.Request)
  11. }
  12. type middlewareImpl struct{}
  13. var middleService = middlewareImpl{}
  14. func Middleware() IMiddleware {
  15. return IMiddleware(&middleService)
  16. }
  17. func (s *middlewareImpl) MiddlewareCORS(r *ghttp.Request) {
  18. corsOptions := r.Response.DefaultCORSOptions()
  19. // you can set options
  20. //corsOptions.AllowDomain = []string{"goframe.org", "baidu.com"}
  21. r.Response.CORS(corsOptions)
  22. r.Middleware.Next()
  23. }