-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
34 lines (28 loc) · 831 Bytes
/
options.go
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
27
28
29
30
31
32
33
34
package manager
import "html/template"
type Option func(mgr *Manager)
// Stream response directly to client. Reduces memory consumption, but it will not let system send valid 5xx code
// in case of rendering failure.
func Stream() Option {
return func(mgr *Manager) {
mgr.stream = true
}
}
// Cache compiled template. Slightly increases memory usage. Recommended in production environment.
func Cache() Option {
return func(mgr *Manager) {
mgr.cache.enable = true
}
}
// FuncMap sets user-defined functions for templates. For example: Sprig library.
func FuncMap(functions template.FuncMap) Option {
return func(mgr *Manager) {
mgr.funcMap = functions
}
}
// Func adds templates functions to internal map.
func Func(name string, fn interface{}) Option {
return func(mgr *Manager) {
mgr.funcMap[name] = fn
}
}