diff options
| author | Mathias Magnusson <mathias@magnusson.space> | 2026-01-24 00:33:11 +0100 |
|---|---|---|
| committer | Mathias Magnusson <mathias@magnusson.space> | 2026-01-24 00:33:11 +0100 |
| commit | d75bab2ba79d138547a0ea6d3b3be84a89b050a8 (patch) | |
| tree | d00eef48f0332380f66578e761f9d27611f53b66 /cmd/generate/main.go | |
| parent | 8f29959b87b68e76aadbc32dfa00f938604b1f6d (diff) | |
| download | hh-d75bab2ba79d138547a0ea6d3b3be84a89b050a8.tar.gz | |
take `http.ResponseWriter` as part of parsed request
Diffstat (limited to 'cmd/generate/main.go')
| -rw-r--r-- | cmd/generate/main.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/cmd/generate/main.go b/cmd/generate/main.go index feed0f0..eddd4cb 100644 --- a/cmd/generate/main.go +++ b/cmd/generate/main.go @@ -123,7 +123,10 @@ func run() error { if pattern, ok = strings.CutPrefix(hhRoute, "//hh:route "); !ok { continue } - parsedRequestType, ok := f.Type.Params.List[1].Type.(*ast.StructType) + if len(f.Type.Params.List) != 1 { + return errors.New("Handler must take exactly one parameter") + } + parsedRequestType, ok := f.Type.Params.List[0].Type.(*ast.StructType) if !ok { return errors.New("Parsed request type must be a struct") } @@ -165,7 +168,7 @@ func run() error { winner, ) } - if parsedField.TypeDef == "*http.Request" { + if parsedField.TypeDef == "*http.Request" || parsedField.TypeDef == "http.ResponseWriter" { parsedFunction.RequestTypeFields = append(parsedFunction.RequestTypeFields, parsedField) continue } |
