muxt generate --output-multiple-files panics when a template has no file of its own, for example one added with template.New("GET /health Health()").Parse(...).
panic: runtime error: index out of range [0] with length 0
github.com/typelate/muxt/internal/generate.accumulateReceiverMethods.func1(...)
slices.IndexFunc[...](...)
github.com/typelate/muxt/internal/generate.accumulateReceiverMethods(...)
github.com/typelate/muxt/internal/generate.hydrateGroup(...)
github.com/typelate/muxt/internal/generate.TemplateRoutesFiles(...)
accumulateReceiverMethods reads field.Names[0].Name for every field in the receiver interface. With --output-multiple-files the main file's interface embeds the per-file interfaces, and an embedded field has no Names, so the lookup panics as soon as a route in the main file adds a method.
Reproduced with a binary built from f7e9368:
module server, index.gohtml holding {{define "GET /{$} Home()"}}, and
var templates = template.Must(template.Must(template.ParseFS(templateFiles, "*.gohtml")).
New("GET /health Health()").Parse(`ok`))
muxt generate --use-receiver-type=T --output-multiple-files
Found while writing snapshot tests for --output-multiple-files; the archive in #151 documents only what does work, because this case panics.
muxt generate --output-multiple-filespanics when a template has no file of its own, for example one added withtemplate.New("GET /health Health()").Parse(...).accumulateReceiverMethodsreadsfield.Names[0].Namefor every field in the receiver interface. With--output-multiple-filesthe main file's interface embeds the per-file interfaces, and an embedded field has noNames, so the lookup panics as soon as a route in the main file adds a method.Reproduced with a binary built from f7e9368:
Found while writing snapshot tests for
--output-multiple-files; the archive in #151 documents only what does work, because this case panics.