| 123456789101112131415161718192021222324252627282930 |
- /*
- * @desc:中间件处理
- * @company:云南奇讯科技有限公司
- * @Author: yixiaohu<yxh669@qq.com>
- * @Date: 2022/3/17 9:11
- */
- package service
- import "github.com/gogf/gf/v2/net/ghttp"
- type IMiddleware interface {
- MiddlewareCORS(r *ghttp.Request)
- }
- type middlewareImpl struct{}
- var middleService = middlewareImpl{}
- func Middleware() IMiddleware {
- return IMiddleware(&middleService)
- }
- func (s *middlewareImpl) MiddlewareCORS(r *ghttp.Request) {
- corsOptions := r.Response.DefaultCORSOptions()
- // you can set options
- //corsOptions.AllowDomain = []string{"goframe.org", "baidu.com"}
- r.Response.CORS(corsOptions)
- r.Middleware.Next()
- }
|