|
|
|
|
|
by rogpeppe1
4595 days ago
|
|
Nice package. I like the fact that it's limited in scope and actually does some work for you. There's a trick you're missing though - you require the user to pass in their expected params struct explicitly so you can reflect on its type, but you could just reflect on the handler function type itself. Then a handler function could look like this: func Do(w http.ResponseWriter, r *http.Request, params *DoParams) {
w.Write([]byte(params.Var))
}
No need for any dynamic type coercion - it can all be checked up front when the handlers are registered. The down side is that the signature of Handle would become more opaque (its argument would just be an interface{}) and you'd probably want to lose the Handler type.FWIW, passing an empty struct for the sole purpose of being inspected using reflection is not unusual (see for example gob.Register). |
|
This is one of the things I don't like about go but really you need a type system like haskell's to achieve what I want here.