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
+5 -3
View File
@@ -10,9 +10,10 @@ import (
type Fun struct {
methods map[string]methodInfo
boxes *sync.Map // 依赖容器:reflect.Type → reflect.Value
guards []*any // 全局 Guard
serviceGuards map[string][]*any // 服务级 Guard,按服务名
routes map[string]RouteHandler // 自定义路由:"GET /path" → 处理器
boxes *sync.Map // 依赖容器:reflect.Type → reflect.Value
guards []*any // 全局 Guard
serviceGuards map[string][]*any // 服务级 Guard,按服务名
}
var (
@@ -33,6 +34,7 @@ type methodInfo struct {
func New() *Fun {
f := &Fun{
methods: map[string]methodInfo{},
routes: map[string]RouteHandler{},
boxes: &sync.Map{},
serviceGuards: map[string][]*any{},
}