/
utils.go
80 lines (66 loc) · 1.36 KB
/
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
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
package main
import (
"os"
"strings"
)
// exists returns whether a folder exists or not in the filesystem
func exists(path string) bool {
_, err := os.Stat(path)
if err != nil || os.IsNotExist(err) {
return false
}
return true
}
// envany returns the first non empty value of a set of
// environment variables
func envany(key ...string) string {
for _, v := range key {
if s := strings.TrimSpace(os.Getenv(v)); s != "" {
return s
}
}
return ""
}
// firstNonEmpty returns the first non-empty string
// and if all strings are empty, it returns the defval
func firstNonEmpty(defval string, value ...string) string {
for _, v := range value {
if v != "" {
return v
}
}
return defval
}
var availableColors = map[string]struct{}{
"cyan": {},
"teal": {},
"green": {},
"light": {},
"lime": {},
"yellow": {},
"amber": {},
"orange": {},
"brown": {},
"grey": {},
"deep": {},
"red": {},
"purple": {},
"blue": {},
"indigo": {},
"pink": {},
}
// isAvailableColor returns true or false depending on if the available color
// exists in getmdl.io
func isAvailableColor(colorCouple string) bool {
items := strings.Split(colorCouple, "-")
if len(items) != 2 {
return false
}
if _, found := availableColors[items[0]]; !found {
return false
}
if _, found := availableColors[items[1]]; !found {
return false
}
return true
}