-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Description
Problem: Using variadic functions within text/templates there presently not a clean way to drop a defined slice into that function. Attempts to do so result in:
wrong type for value. Expected string, got []stringDirect usage of the spread operator valid in a go code context leads to a syntax error within a template context:
unexpected <.> in operandI can imagine two solutions to this problem. Either a "spread" builtin template function that can be dropped ahead of the struct to "spread" the a generic slice in a manner identical to the ellipsis notation but valid within a template context, or automatic type flexibility that allows variadic template funcs to process slices of the same type T as though they were valid variadic types.
Present Workaround:
Presently the only way I am aware of to work around this problem is to create a func wrapper.
// variadic func in question
func variadicFunc(s ...string) output {
....
}
func wrapperFunc(s []string) output {
return variadicFunc(s...)
}If there are better workarounds, let me know. Otherwise, my humble thanks for considering this feature request.