Skip to content

Latest commit

 

History

History
33 lines (31 loc) · 3.66 KB

funcs.md

File metadata and controls

33 lines (31 loc) · 3.66 KB

Functions for a template

knife provides functions which can be use in a template.

Function Example Description
pkg {{pkg}} target package
br {{br}} new line
array {{(array .).Len}} convert type to knife.Array
see: knife.ToArray
basic {{(basic .).Kind}} convert type to knife.Basic
see: knife.ToBasic
chan {{(chan .).Dir}} convert type to knife.Chan
see: knife.ToChan
interface {{(interface .).Methods}} convert type to knife.Interface
see: knife.ToInterface
map {{(map .).Key}} convert type to knife.Map
see: knife.ToMap
named {{(named .).Methods}} convert type to knife.Named
see: knife.ToNamed
pointer {{(pointer .).Elem}} convert type to knife.Pointer
see: knife.ToPointer
ptr {{(ptr .).Elem}} same as pointer
signature {{(signature .).Recv}} convert type to knife.Signature
see: knife.ToSignature
slice {{(slice .).Elem}} convert type to knife.Slice
see: knife.ToSlice
struct {{(struct .).Fields}} convert type to knife.Struct
see: knife.ToStruct
len {{len .}} len(x) calls reflect.ValueOf(x).Len()
cap {{cap .}} cap(x) calls reflect.ValueOf(x).Cap()
last {{last .}} last(x) returns last element of a slice, array or string
exported {{exported .Types}} exported filters out unexported objects
methods {{methods .Types.T}} methods returns methods of the type
names {{range names .Types}}{{.}}{{end}} slice, array or map of Name field
implements {{if implements . (typeof "error")}}{{.}}{{end}} implements reports whether the type implements the interface
identical {{if identical . (typeof "error")}}{{.}}{{end}} identical reports whether the two types are identical types
under {{under .Types.T}} under returns an underlying type of the type recursively
pos {{pos .}} pos returns token.Position by calling Pos methods
objectof {{objectof "panic"}} objectof returns knife.Object which is specified by name
typeof {{typeof "error"}} typeof returns *knife.Type which is specified by name
doc {{doc .Types.T}} doc returns corresponding document to the object
data {{data "key"}} data returns extra data which given via knife.Option