fun: add BindRoute for custom HTTP routes (GET/POST, form-data callbacks)
- BindRoute(method, path, handler) with exact-match routing dispatched before /cell RPC - RouteCtx merges query args and form-urlencoded POST args for callback scenarios (e.g. epay notify) - handler returns error -> unified Result error response; nil -> full control via fasthttp.RequestCtx (plain-text 'success' replies) - /cell reserved; duplicate/invalid registration panics at startup; all existing tests pass
This commit is contained in:
@@ -11,11 +11,16 @@ import (
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// handle 处理 HTTP 请求
|
||||
// handle 处理 HTTP 请求:先匹配自定义路由(BindRoute),未命中走 /cell RPC
|
||||
func (f *Fun) handle(fastCtx *fasthttp.RequestCtx) {
|
||||
ctx := &Ctx{RequestCtx: fastCtx}
|
||||
defer f.handlePanic(ctx)
|
||||
|
||||
if handler, ok := f.routes[string(fastCtx.Method())+" "+string(fastCtx.Path())]; ok {
|
||||
f.handleRoute(fastCtx, handler)
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.path() != "/cell" {
|
||||
ctx.setStatusCode(fasthttp.StatusNotFound)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user