forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
88 lines (75 loc) · 1.26 KB
/
helper.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
86
87
88
package modules
import (
"html/template"
"strconv"
uuid "github.com/satori/go.uuid"
)
func InArray(arr []string, str string) bool {
for _, v := range arr {
if v == str {
return true
}
}
return false
}
func Delimiter(del, del2, s string) string {
return del + s + del2
}
func FilterField(filed, delimiter, delimiter2 string) string {
return delimiter + filed + delimiter2
}
func InArrayWithoutEmpty(arr []string, str string) bool {
if len(arr) == 0 {
return true
}
for _, v := range arr {
if v == str {
return true
}
}
return false
}
func RemoveBlankFromArray(s []string) []string {
var r []string
for _, str := range s {
if str != "" {
r = append(r, str)
}
}
return r
}
func Uuid() string {
return uuid.NewV4().String()
}
func SetDefault(source, def string) string {
if source == "" {
return def
}
return source
}
func GetPage(page string) (pageInt int) {
if page == "" {
pageInt = 1
} else {
pageInt, _ = strconv.Atoi(page)
}
return
}
func AorB(condition bool, a, b string) string {
if condition {
return a
}
return b
}
func AorEmpty(condition bool, a string) string {
if condition {
return a
}
return ""
}
func AorBHTML(condition bool, a, b template.HTML) template.HTML {
if condition {
return a
}
return b
}