forked from kaptinlin/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.go
More file actions
26 lines (22 loc) · 733 Bytes
/
engine.go
File metadata and controls
26 lines (22 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package template
// Parse parses a template string and returns a Template instance.
func Parse(source string) (*Template, error) {
parser := NewParser()
return parser.Parse(source)
}
// Execute renders the template with provided context.
func Execute(tpl *Template, ctx Context) (string, error) {
return tpl.Execute(ctx)
}
// MustExecute renders the template with provided context, ignoring errors.
func MustExecute(tpl *Template, ctx Context) string {
return tpl.MustExecute(ctx)
}
// Render combines parsing and executing a template with the given context for convenience.
func Render(source string, ctx Context) (string, error) {
tpl, err := Parse(source)
if err != nil {
return "", err
}
return Execute(tpl, ctx)
}