-
Notifications
You must be signed in to change notification settings - Fork 9
How to use easygen API
suntong edited this page Aug 3, 2020
·
5 revisions
easygen's API has been the same since V2. I.e., use easygen.NewTemplate()
to init a new template:
tmpl := easygen.NewTemplate().Funcs(easygen.FuncDefs())
then use easygen.Execute()
:
err := easygen.Execute(tmpl, os.Stdout, templateFile, settingVar)
Or, to get the result into variable, use the following:
buf := new(bytes.Buffer)
err := easygen.Execute(tmpl, buf, templateFile, settingVar)
check(err)
return buf.String()
to directly use template string instead of template file, use the following:
buf := new(bytes.Buffer)
err := easygen.Process0(tmpl, buf, templateStr, yamlFileName)
See also,