Sprig provides rudimentary reflection tools. These help advanced template developers understand the underlying Go type information for a particular value.
Go has several primitive kinds, like
Go has an open type system that allows developers to create their own types.
Sprig provides a set of functions for each.
There are two Kind functions:
kindOf returns the kind of an object.
The above would return
string. For simple tests (like in
if blocks), the
isKind function will let you verify that a value is a particular kind:
kindIs "int" 123
The above will return
Types are slightly harder to work with, so there are three different functions:
typeOfreturns the underlying type of a value:
kindIs, but for types:
typeIs "*io.Buffer" $myVal
kindIs, except that it also dereferences pointers.
Note: None of these can test whether or not something implements a given interface, since doing so would require compiling the interface in ahead of time.