-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbilet.go
52 lines (44 loc) · 921 Bytes
/
bilet.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
package bilit
import (
"log"
"os"
"regexp"
)
var (
// DefaultPattern is the default pattern for the regex
DefaultPattern = ".+"
// Debug enables printing of the map passed to a template
Debug = false
// Unsafe disables RegExp escaping
Unsafe = false
out = log.New(os.Stdout, "", log.Lshortfile)
)
func init() {
out.SetPrefix("[bilit] ")
if Debug {
out.SetPrefix("[bilit (DEBUG)] ")
}
}
// Tmpl is a bilit template
type Tmpl struct {
template string
pattern string
regex *regexp.Regexp
}
// RegEx makes the pull regular expression
func (t Tmpl) RegEx() *regexp.Regexp {
t.regex = regexp.MustCompile(pullRegex(t.template, t.pattern))
return t.regex
}
// Template makes a template
func Template(str string, pattern ...string) Tmpl {
if len(pattern) == 0 {
pattern = append(pattern, DefaultPattern)
}
var obj = Tmpl{
template: str,
pattern: pattern[0],
}
obj.RegEx()
return obj
}