/
funcmap.go
85 lines (74 loc) · 1.76 KB
/
funcmap.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package tmpl
import (
"github.com/major1201/goutils"
htmlTemplate "html/template"
"os"
"strings"
textTemplate "text/template"
)
// FuncMap a common template tmpl implement
type FuncMap map[string]interface{}
// TextFuncMap convert to text template funcMap
func (fm FuncMap) TextFuncMap() textTemplate.FuncMap {
return textTemplate.FuncMap(fm)
}
// HTMLFuncMap convert to html template funcMap
func (fm FuncMap) HTMLFuncMap() htmlTemplate.FuncMap {
return htmlTemplate.FuncMap(fm)
}
// GetFuncMap returns the common funcMap
func GetFuncMap() FuncMap {
return fm
}
var fm = FuncMap{
// numbers
"int": goutils.ToInt,
"intdv": goutils.ToIntDv,
"inc": inc,
"add": add,
"sub": sub,
"mul": mul,
"div": div,
"mod": mod,
"rand": random,
// strings
"title": strings.Title,
"replaceall": strings.ReplaceAll,
"trim": goutils.Trim,
"trimleft": goutils.TrimLeft,
"trimright": goutils.TrimRight,
"upper": strings.ToUpper,
"lower": strings.ToLower,
"join": join,
"split": split,
"hasprefix": hasPrefix,
"hassuffix": hasSuffix,
"between": goutils.Between,
"contains": contains,
"indent": indent,
"uuid": goutils.UUID,
"filesize": goutils.FileSize,
"leftpad": goutils.LeftPad,
"rightpad": goutils.RightPad,
// bool
"bool": goutils.ToBool,
"booldv": goutils.ToBoolDv,
// encoding
"base64en": encodeBase64,
"base64de": decodeBase64,
"md5": encodeMd5,
"sha1": encodeSha1,
"sha224": encodeSha224,
"sha256": encodeSha256,
"sha512": encodeSha512,
"json": toJSON,
"prettyjson": toPrettyJSON,
"yaml": toYAML,
// system
"debug": debug,
"env": os.Getenv,
"idx": index,
// kubernetes
"mulquantity": mulQuantity,
"divquantity": divQuantity,
}