feat: 新增参数绑定接口

main
熊二 2 years ago
parent b41fdd7816
commit 460dc378ea
  1. 7
      app/net.go

@ -13,6 +13,11 @@ type Convertor[V any] func(s string) (V, error)
type HandlerFunc func(w *ResponseWriter, r *Request)
type ParamGetter func(key string) (string, bool)
// Binder 参数绑定接口
type Binder interface {
Bind(r *Request) error
}
func GetParam[V any](r *Params, key string, def V, convertor Convertor[V], taps []TapFunc[V]) V {
var v V
if str, ok := r.Get(key); ok {
@ -125,7 +130,6 @@ func (u *Params) Float64(key string, def float64, taps ...TapFunc[float64]) floa
}, taps)
}
type Request struct {
*http.Request
*Params
@ -265,4 +269,3 @@ func Handler(hf HandlerFunc) http.HandlerFunc {
hf(NewResponseWriter(w), NewRequest(r))
}
}

Loading…
Cancel
Save