forked from SebastiaanKlippert/go-foxpro-dbf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cast.go
56 lines (48 loc) · 1.01 KB
/
cast.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
package dbf
import (
"strings"
"time"
)
// This file contains some helper casting functions for the interface values returned from the field methods.
// ToString always returns a string
func ToString(in interface{}) string {
if str, ok := in.(string); ok {
return str
}
return ""
}
// ToTrimmedString always returns a string with spaces trimmed
func ToTrimmedString(in interface{}) string {
if str, ok := in.(string); ok {
return strings.TrimSpace(str)
}
return ""
}
// ToInt64 always returns an int64
func ToInt64(in interface{}) int64 {
if i, ok := in.(int64); ok {
return i
}
return 0
}
// ToFloat64 always returns a float64
func ToFloat64(in interface{}) float64 {
if f, ok := in.(float64); ok {
return f
}
return 0.0
}
// ToTime always returns a time.Time
func ToTime(in interface{}) time.Time {
if t, ok := in.(time.Time); ok {
return t
}
return time.Time{}
}
// ToBool always returns a boolean
func ToBool(in interface{}) bool {
if b, ok := in.(bool); ok {
return b
}
return false
}