blob: d03150d6b6ea00526387a63931b9dd8c74ce5ead (
plain)
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
|
package mappers
import "strconv"
func ForceString(s any) string {
switch v := s.(type) {
case string:
return v
case int:
return strconv.Itoa(v)
case int64:
return strconv.FormatInt(v, 10)
case float64:
return strconv.FormatFloat(v, 'f', -1, 64)
case bool:
if v {
return "true"
}
return "false"
default:
return ""
}
}
func ForceInt(s any) int {
switch v := s.(type) {
case string:
i, err := strconv.Atoi(v)
if err != nil {
return 0
}
return i
case int:
return v
case int64:
return int(v)
case float64:
return int(v)
case bool:
if v {
return 1
}
return 0
default:
return 0
}
}
|