-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemplates.go
More file actions
43 lines (38 loc) · 723 Bytes
/
Copy pathtemplates.go
File metadata and controls
43 lines (38 loc) · 723 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"text/template"
)
func tplString(i interface{}) string {
if str, ok := i.([]byte); ok {
return string(str)
} else {
return "<UNCOMPATIBLE DATA>"
}
}
func tplRange2(block []*Block) [][]Block {
var ret [][]Block
tmp := make([]Block, 2)
tmp[0] = *block[0]
ret = append(ret, tmp)
for i := 1; i < len(block); i += 2 {
tmp := make([]Block, 2)
tmp[0] = *block[i]
if i+1 < len(block) && block != nil {
tmp[1] = *block[i+1]
}
ret = append(ret, tmp)
}
return ret
}
func tplAdd(i, v int) int {
ret := i + v
return ret
}
func tplGetFuncMap() template.FuncMap {
return template.FuncMap{
"String": tplString,
"Add": tplAdd,
// "Hex": tplHex,
"Range2": tplRange2,
}
}