middleware.go 642 B

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