-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathutils.go
59 lines (45 loc) · 986 Bytes
/
utils.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
package goexpose
import (
"bytes"
"strings"
"text/template"
)
/*
Returns if method is allowed
if avail methods is blank it also returns true
*/
func MethodAllowed(method string, avail []string) bool {
if len(avail) == 0 {
return true
}
for _, am := range avail {
if strings.ToUpper(method) == strings.ToUpper(am) {
return true
}
}
return false
}
/*
Interpolate
renders template with data
*/
func Interpolate(strTemplate string, data map[string]interface{}) (result string, err error) {
var tpl *template.Template
// compile url to template
if tpl, err = template.New("anonym-template").Parse(strTemplate); err != nil {
return
}
return RenderTemplate(tpl, data)
}
/*
RenderTemplate
renders template with data
*/
func RenderTemplate(tpl *template.Template, data map[string]interface{}) (result string, err error) {
b := bytes.NewBuffer([]byte{})
// interpolate url
if err = tpl.Execute(b, data); err != nil {
return
}
return b.String(), nil
}