forked from codeamp/circuit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
48 lines (39 loc) · 940 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
package plugins
import (
"regexp"
"github.com/extemporalgenome/slug"
)
func GetRegexParams(regEx, url string) (paramsMap map[string]string) {
var compRegEx = regexp.MustCompile(regEx)
match := compRegEx.FindStringSubmatch(url)
paramsMap = make(map[string]string)
for i, name := range compRegEx.SubexpNames() {
if i > 0 && i <= len(match) {
paramsMap[name] = match[i]
}
}
return
}
func HstoreToMapStringString(hstore map[string]*string) map[string]string {
mapStringString := map[string]string{}
for k, v := range hstore {
if k == "" || *v == "" {
continue
}
mapStringString[k] = *v
}
return mapStringString
}
func MapStringStringToHstore(mapStringString map[string]string) map[string]*string {
hstore := map[string]*string{}
for k, v := range mapStringString {
if k == "" || v == "" {
continue
}
hstore[k] = &v
}
return hstore
}
func GetSlug(name string) string {
return slug.Slug(name)
}