-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtypes.go
More file actions
41 lines (35 loc) · 700 Bytes
/
Copy pathtypes.go
File metadata and controls
41 lines (35 loc) · 700 Bytes
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
package keyvalues
import (
"strconv"
"strings"
)
type ValueType string
const ValueString = ValueType("string")
const ValueInt = ValueType("integer")
const ValueArray = ValueType("array")
const ValuePtr = ValueType("ptr")
const ValueFloat = ValueType("float")
func getType(val string) ValueType {
switch true {
case isFloat(val):
return ValueFloat
case isInt(val):
return ValueInt
default:
return ValueString
}
}
func isInt(val string) bool {
if _, err := strconv.Atoi(val); err == nil {
return true
}
return false
}
func isFloat(val string) bool {
if _, err := strconv.ParseFloat(val, 32); err == nil {
if strings.Contains(val, ".") {
return true
}
}
return false
}