mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-18 18:34:45 +08:00
support httpservice request filtrate.
This commit is contained in:
@@ -36,10 +36,11 @@ type HttpServerService struct {
|
|||||||
httpserver network.HttpServer
|
httpserver network.HttpServer
|
||||||
port uint16
|
port uint16
|
||||||
|
|
||||||
controllerMaps ControllerMapsType
|
controllerMaps ControllerMapsType
|
||||||
certfile string
|
certfile string
|
||||||
keyfile string
|
keyfile string
|
||||||
ishttps bool
|
ishttps bool
|
||||||
|
httpfiltrateList []HttpFiltrate
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *HttpServerService) OnInit() error {
|
func (slf *HttpServerService) OnInit() error {
|
||||||
@@ -62,6 +63,14 @@ func (slf *HttpServerService) initRouterHandler() http.Handler {
|
|||||||
return cors.Handler(r)
|
return cors.Handler(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HttpFiltrate func(path string, w http.ResponseWriter, r *http.Request) error
|
||||||
|
|
||||||
|
func (slf *HttpServerService) AppendHttpFiltrate(fun HttpFiltrate) bool {
|
||||||
|
slf.httpfiltrateList = append(slf.httpfiltrateList, fun)
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (slf *HttpServerService) OnRun() bool {
|
func (slf *HttpServerService) OnRun() bool {
|
||||||
|
|
||||||
slf.httpserver.Start()
|
slf.httpserver.Start()
|
||||||
@@ -106,6 +115,21 @@ func (slf *HttpServerService) httpHandler(w http.ResponseWriter, r *http.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 在这儿处理例外路由接口
|
// 在这儿处理例外路由接口
|
||||||
|
var errRet error
|
||||||
|
for _, filter := range slf.httpfiltrateList {
|
||||||
|
ret := filter(r.URL.Path, w, r)
|
||||||
|
if ret == nil {
|
||||||
|
errRet = nil
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
errRet = ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if errRet != nil {
|
||||||
|
writeError(http.StatusBadRequest, errRet.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 拼接得到rpc服务的名称
|
// 拼接得到rpc服务的名称
|
||||||
vstr := strings.Split(r.URL.Path, "/")
|
vstr := strings.Split(r.URL.Path, "/")
|
||||||
|
|||||||
Reference in New Issue
Block a user