- 约束handler入参和返回为func(ctx, req) (resp, error)。
- 通过反射,封装handler,在调用前后写入入参和返回的处理。
package testing
import (
"context"
"fmt"
"reflect"
"strings"
"testing"
)
type ReqParams struct {
Name string
Age int
}
type RouteHandlers struct{
}
func (r *RouteHandlers) Test(c *context.Context, req *ReqParams) {
fmt.Println("req:", req)
}
type Router struct {
Method reflect.Value // 请求中的handler
Params reflect.Value // 请求参数
}
func

最低0.47元/天 解锁文章
2584

被折叠的 条评论
为什么被折叠?



