mirror of
https://github.com/tiger1103/gfast.git
synced 2026-10-02 13:35:05 +00:00
31 lines
650 B
Go
31 lines
650 B
Go
/*
|
|
* @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()
|
|
}
|