-
Notifications
You must be signed in to change notification settings - Fork 20
/
util.go
42 lines (33 loc) · 851 Bytes
/
util.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
package cmd
// isInList returns true if v exists in the specified list, false otherwise.
func isInList(list []string, v string) bool {
for _, lv := range list {
if lv == v {
return true
}
}
return false
}
// ellipString truncates the string s with an ellipsis character if longer
// than maxLen.
func ellipString(s string, maxLen int) string {
ellipsis := "…"
if len(s) > maxLen {
return s[0:maxLen-1] + ellipsis
}
return s
}
// defaultString returns the value of the string pointer s if not nil, otherwise the default value specified.
func defaultString(s *string, def string) string {
if s != nil {
return *s
}
return def
}
// defaultBool returns the value of the bool pointer b if not nil, otherwise the default value specified.
func defaultBool(b *bool, def bool) bool {
if b != nil {
return *b
}
return def
}