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:
2026-08-20 10:17:56 +08:00
parent 4bf991b3e7
commit 05af3dc825
4 changed files with 216 additions and 4 deletions
+6 -1
View File
@@ -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