mirror of
https://github.com/eolinker/apinto
synced 2026-04-22 16:07:04 +08:00
前置路由
This commit is contained in:
@@ -31,7 +31,7 @@ type dubboHandler struct {
|
||||
|
||||
var completeCaller = manager.NewCompleteCaller()
|
||||
|
||||
func (d *dubboHandler) ServeHTTP(ctx eocontext.EoContext) {
|
||||
func (d *dubboHandler) Serve(ctx eocontext.EoContext) {
|
||||
|
||||
dubboCtx, err := dubbo2_context.Assert(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -93,7 +93,7 @@ func (d *dubboManger) Handler(port int, req *invocation.RPCInvocation) protocol.
|
||||
|
||||
} else {
|
||||
log.Debug("match has:", port)
|
||||
match.ServeHTTP(ctx)
|
||||
match.Serve(ctx)
|
||||
}
|
||||
|
||||
finish := ctx.GetFinish()
|
||||
|
||||
@@ -31,7 +31,7 @@ type grpcRouter struct {
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func (h *grpcRouter) ServeHTTP(ctx eocontext.EoContext) {
|
||||
func (h *grpcRouter) Serve(ctx eocontext.EoContext) {
|
||||
grpcContext, err := grpc_context.Assert(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -85,7 +85,7 @@ func (m *Manager) FastHandler(port int, srv interface{}, stream grpc.ServerStrea
|
||||
}
|
||||
} else {
|
||||
log.Debug("match has:", port)
|
||||
r.ServeHTTP(ctx)
|
||||
r.Serve(ctx)
|
||||
}
|
||||
|
||||
finishHandler := ctx.GetFinish()
|
||||
|
||||
@@ -34,7 +34,7 @@ type httpHandler struct {
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func (h *httpHandler) ServeHTTP(ctx eocontext.EoContext) {
|
||||
func (h *httpHandler) Serve(ctx eocontext.EoContext) {
|
||||
httpContext, err := http_context.Assert(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
chainProxy eocontext.IChainPro
|
||||
chainProxy eocontext.IChainPro
|
||||
routerManager = NewManager()
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
var routerManager = NewManager()
|
||||
serverHandler := func(port int, ln net.Listener) {
|
||||
server := fasthttp.Server{
|
||||
StreamRequestBody: true,
|
||||
|
||||
@@ -20,8 +20,12 @@ var completeCaller = http_complete.NewHttpCompleteCaller()
|
||||
type IManger interface {
|
||||
Set(id string, port int, hosts []string, method []string, path string, append []AppendRule, router router.IRouterHandler) error
|
||||
Delete(id string)
|
||||
AddPreRouter(id string, method []string, path string, handler router.IRouterPreHandler)
|
||||
DeletePreRouter(id string)
|
||||
}
|
||||
|
||||
type Manager struct {
|
||||
IPreRouterData
|
||||
lock sync.RWMutex
|
||||
matcher router.IMatcher
|
||||
|
||||
@@ -35,7 +39,8 @@ func (m *Manager) SetGlobalFilters(globalFilters *eoscContext.IChainPro) {
|
||||
|
||||
// NewManager 创建路由管理器
|
||||
func NewManager() *Manager {
|
||||
return &Manager{routersData: new(RouterData)}
|
||||
return &Manager{routersData: new(RouterData),
|
||||
IPreRouterData: newImlPreRouterData()}
|
||||
}
|
||||
|
||||
func (m *Manager) Set(id string, port int, hosts []string, method []string, path string, append []AppendRule, router router.IRouterHandler) error {
|
||||
@@ -88,7 +93,7 @@ func (m *Manager) FastHandler(port int, ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
} else {
|
||||
log.Debug("match has:", port)
|
||||
r.ServeHTTP(httpContext)
|
||||
r.Serve(httpContext)
|
||||
}
|
||||
finishHandler := httpContext.GetFinish()
|
||||
if finishHandler != nil {
|
||||
|
||||
+5
-1
@@ -9,5 +9,9 @@ type IMatcher interface {
|
||||
}
|
||||
|
||||
type IRouterHandler interface {
|
||||
ServeHTTP(ctx eoscContext.EoContext)
|
||||
Serve(ctx eoscContext.EoContext)
|
||||
}
|
||||
|
||||
type IRouterPreHandler interface {
|
||||
Server(ctx eoscContext.EoContext) (isContinue bool)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user