Files
apinto/drivers/router/http-router/handler.go
2022-09-16 15:06:51 +08:00

38 lines
934 B
Go

package http_router
import (
"github.com/eolinker/apinto/drivers/router"
"github.com/eolinker/apinto/service"
"github.com/eolinker/eosc/eocontext"
http_context "github.com/eolinker/eosc/eocontext/http-context"
"net/http"
)
var completeCaller = router.NewHttpCompleteCaller()
type Handler struct {
completeHandler *router.HttpComplete
finisher Finisher
service service.IService
filters eocontext.IChainPro
disable bool
}
func (h *Handler) ServeHTTP(ctx eocontext.EoContext) {
if h.disable {
httpContext, err := http_context.Assert(ctx)
if err != nil {
return
}
httpContext.Response().SetStatus(http.StatusNotFound, "")
httpContext.Response().SetBody([]byte("router disable"))
httpContext.FastFinish()
return
}
ctx.SetFinish(&h.finisher)
ctx.SetCompleteHandler(h.completeHandler)
ctx.SetApp(h.service)
ctx.SetBalance(h.service)
h.filters.Chain(ctx, completeCaller)
}