gotemplate
gotemplate copied to clipboard
generate single file for multiple data type
package max
// template type Max(A)
type A int
func Max(x, y A) A {
if x < y {
return y
}
return x
}
for above template, is ok to generate multiple files.
//go:generate gotemplate "xxx/max" "MaxInt(int)"
//go:generate gotemplate "xxx/max" "MaxInt8(int8)"
//go:generate gotemplate "xxx/max" "MaxInt16(int16)"
//go:generate gotemplate "xxx/max" "MaxInt32(int32)"
//go:generate gotemplate "xxx/max" "MaxInt64(int64)"
since the template is too simple, it's better to organize these functions into a single file.
is it possible to accept multiple arguments something like this?
// go:generate gotemplate -out "MaxInts" "xxx/max" "MaxInt(int)" "MaxInt8(int8)" "MaxInt16(int16)" "MaxInt32(int32)" "MaxInt64(int64)"
This isn't possible at the moment, but it doesn't sound too difficult... Fancy sending a PR?