forked from asaskevich/govalidator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconverter_example_test.go
35 lines (29 loc) · 971 Bytes
/
converter_example_test.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
package govalidator
import "time"
func ExampleToBoolean() {
// Returns the boolean value represented by the string.
// It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
// Any other value returns an error.
_, _ = ToBoolean("false") // false, nil
_, _ = ToBoolean("T") // true, nil
_, _ = ToBoolean("123123") // false, error
}
func ExampleToInt() {
_, _ = ToInt(1.0) // 1, nil
_, _ = ToInt("-124") // -124, nil
_, _ = ToInt("false") // 0, error
}
func ExampleToFloat() {
_, _ = ToFloat("-124.2e123") // -124.2e123, nil
_, _ = ToFloat("false") // 0, error
}
func ExampleToString() {
_ = ToString(new(interface{})) // 0xc000090200
_ = ToString(time.Second + time.Hour) // 1h1s
_ = ToString(123) // 123
}
func ExampleToJSON() {
_, _ = ToJSON([]int{1, 2, 3}) // [1, 2, 3]
_, _ = ToJSON(map[int]int{1: 2, 2: 3}) // { "1": 2, "2": 3 }
_, _ = ToJSON(func() {}) // error
}