-
-
Notifications
You must be signed in to change notification settings - Fork 232
Open
Description
Hi there, I'm trying to create a resuable wrapper function that can do some common logic against the *http.Request. Below is my attempt:
// RequestAware will try to capture the http.Request from the huma.Context by implementing the huma.Resolver interface
type RequestAware struct {
*http.Request
}
func (i *RequestAware) Resolve(ctx huma.Context) []error {
i.Request, _ = humago.Unwrap(ctx)
return nil
}
// Here I'm struggling to get the Input value
type Blended[I any] struct {
RequestAware
Input I
}
// The wrapper function
func Wrapper[I, O any](
handler func(context.Context, *I) (*O, error),
) func(context.Context, *Blended[I]) (*O, error) {
return func(ctx context.Context, t *Blended[I]) (*O, error) {
doSomethingWithRequest(t.Request)
return handler(ctx, &t.Input)
}
}In the above example, I'm struggling to get the Input value. The type [I] in my first registered handler, is like this:
struct {
Body struct {
V int `json:"v"`
}
}I can however successfully capture the *http.Request. Is it because that the I is not embedded in the Blended struct ? But there's no way to embed a generic type parameter currently AFAIK.
Can someone please help me, guide me out of this storm, please! Thank you beforehand!
Metadata
Metadata
Assignees
Labels
No labels