-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
types.go
37 lines (31 loc) · 896 Bytes
/
types.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
package config
import (
"strconv"
"strings"
)
// typeConvertor is a struct that will convert a string to a specific type
type typeConvertor struct {
str string
}
// StringArray will return a string array from a comma separated string
func (t typeConvertor) StringArray() []string {
allUpdates := strings.Split(t.str, ",")
for i, j := range allUpdates {
allUpdates[i] = strings.TrimSpace(j) // this will trim the whitespace
}
return allUpdates
}
// IntArray will return an int array from a comma separated string
func (t typeConvertor) Int() int {
val, _ := strconv.Atoi(t.str)
return val
}
// Int64Array will return an int64 array from a comma separated string
func (t typeConvertor) Int64() int64 {
val, _ := strconv.ParseInt(t.str, 10, 64)
return val
}
// Bool will return a bool from a string
func (t typeConvertor) Bool() bool {
return t.str == "yes" || t.str == "true"
}