6
6
7
7
// Package gconv implements powerful and convenient converting functionality for any types of variables.
8
8
//
9
- // This package should keep much less dependencies with other packages.
9
+ // This package should keep much fewer dependencies with other packages.
10
10
package gconv
11
11
12
12
import (
@@ -23,7 +23,8 @@ import (
23
23
"github.com/gogf/gf/v2/internal/json"
24
24
"github.com/gogf/gf/v2/internal/reflection"
25
25
"github.com/gogf/gf/v2/os/gtime"
26
- "github.com/gogf/gf/v2/util/gtag"
26
+ "github.com/gogf/gf/v2/util/gconv/internal/localinterface"
27
+ "github.com/gogf/gf/v2/util/gconv/internal/structcache"
27
28
)
28
29
29
30
var (
@@ -35,13 +36,23 @@ var (
35
36
"off" : {},
36
37
"false" : {},
37
38
}
38
-
39
- // StructTagPriority defines the default priority tags for Map*/Struct* functions.
40
- // Note that, the `gconv/param` tags are used by old version of package.
41
- // It is strongly recommended using short tag `c/p` instead in the future.
42
- StructTagPriority = gtag .StructTagPriority
43
39
)
44
40
41
+ func init () {
42
+ // register common converters for internal usage.
43
+ structcache .RegisterCommonConverter (structcache.CommonConverter {
44
+ Int64 : Int64 ,
45
+ Uint64 : Uint64 ,
46
+ String : String ,
47
+ Float32 : Float32 ,
48
+ Float64 : Float64 ,
49
+ Time : Time ,
50
+ GTime : GTime ,
51
+ Bytes : Bytes ,
52
+ Bool : Bool ,
53
+ })
54
+ }
55
+
45
56
// Byte converts `any` to byte.
46
57
func Byte (any interface {}) byte {
47
58
if v , ok := any .(byte ); ok {
@@ -63,7 +74,7 @@ func Bytes(any interface{}) []byte {
63
74
return value
64
75
65
76
default :
66
- if f , ok := value .(iBytes ); ok {
77
+ if f , ok := value .(localinterface. IBytes ); ok {
67
78
return f .Bytes ()
68
79
}
69
80
originValueAndKind := reflection .OriginValueAndKind (any )
@@ -174,12 +185,12 @@ func String(any interface{}) string {
174
185
if value == nil {
175
186
return ""
176
187
}
177
- if f , ok := value .(iString ); ok {
188
+ if f , ok := value .(localinterface. IString ); ok {
178
189
// If the variable implements the String() interface,
179
190
// then use that interface to perform the conversion
180
191
return f .String ()
181
192
}
182
- if f , ok := value .(iError ); ok {
193
+ if f , ok := value .(localinterface. IError ); ok {
183
194
// If the variable implements the Error() interface,
184
195
// then use that interface to perform the conversion
185
196
return f .Error ()
@@ -235,7 +246,7 @@ func Bool(any interface{}) bool {
235
246
}
236
247
return true
237
248
default :
238
- if f , ok := value .(iBool ); ok {
249
+ if f , ok := value .(localinterface. IBool ); ok {
239
250
return f .Bool ()
240
251
}
241
252
rv := reflect .ValueOf (any )
0 commit comments