You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible using only exported symbols to write a type-checker for templates. There is just one missing piece: to check a function call like {{len .}}, the checker needs the function signature, but there is no way to retrieve that from a Template.
To work around this, I copied the information for built-ins from text/template, and I must ask the user to pass to my checker whatever FuncMaps they used when parsing the template. The first solution is brittle and the second unpleasant.
All that is missing is the method Template.LookupFunc(name string) interface{}. It would behave much like the unexported findFunction function in text/template/funcs.go, but it would return the unreflected function value or nil if the name was undefined.
I propose it be added to both text/template.Template and html/template.Template.