Open ncw opened 9 years ago
Picking up this old issue 👍
Could we perhaps combine this with support for multiple templates per package?
Let's assume in a package we want to declare two templates:
// in package github.com/myitcv/allthethings
package allthethings
// template type Set(A)
// template type Ring(A)
It would then be relatively straightforward to group the package's *ast.File
's by these special comments (with some basic handling for mismatched parameters etc)
Then using these templates we could do something like:
//go:generate gotemplate "github.com/myitcv/allthethings" StringSet(string) Set
I've added the template name as an additional parameter for backwards compatibility. Failing to supply a template name when referencing a package that contains multiple templates would be an error. Otherwise, if a package only contains a single template the template name would be optional.
I have to say I'm not entirely convinced of the need to support multiple files per template; I'm much more interested in multiple templates per package. So if you'd prefer I can split the latter into a separate issue.
In
instantiate
we check that only one go file is found for the template. This is an unecessary restriction. What we should do is eithergotemplate__MySet__1.go
,gotemplate__MySet__2.go
gotemplate__MySet__original_name.go
,gotemplate__MySet__other_name.go