-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutil_test.go
107 lines (102 loc) · 1.39 KB
/
util_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package jsonapi_test
import (
"strings"
"time"
)
func makeOneLineNoSpaces(str string) string {
str = strings.ReplaceAll(str, "\t", "")
str = strings.ReplaceAll(str, "\n", "")
return strings.ReplaceAll(str, " ", "")
}
func ptr(v any) any {
switch c := v.(type) {
// String
case string:
return &c
// Integers
case int:
return &c
case int8:
return &c
case int16:
return &c
case int32:
return &c
case int64:
return &c
case uint:
return &c
case uint8:
return &c
case uint16:
return &c
case uint32:
return &c
case uint64:
return &c
// Bool
case bool:
return &c
// time.Time
case time.Time:
return &c
// []byte
case []byte:
return &c
default:
return nil
}
}
func nilptr(t string) any {
switch t {
// String
case "string":
var p *string
return p
// Integers
case "int":
var p *int
return p
case "int8":
var p *int8
return p
case "int16":
var p *int16
return p
case "int32":
var p *int32
return p
case "int64":
var p *int64
return p
case "uint":
var p *uint
return p
case "uint8":
var p *uint8
return p
case "uint16":
var p *uint16
return p
case "uint32":
var p *uint32
return p
case "uint64":
var p *uint64
return p
// Bool
case "bool":
var p *bool
return p
// time.Time
case "time.Time":
var p *time.Time
return p
// []byte
case "[]byte":
var p *[]byte
return p
default:
return nil
}
}