@@ -34,7 +34,7 @@ var ErrNotSupported = errors.New("not supported")
34
34
// - UserPartial (a wrapper by SetUser)
35
35
type User interface {
36
36
// GetRaw should return the raw instance of the user, if supported.
37
- GetRaw () (interface {} , error )
37
+ GetRaw () (any , error )
38
38
// GetAuthorization should return the authorization method,
39
39
// e.g. Basic Authentication.
40
40
GetAuthorization () (string , error )
@@ -60,12 +60,12 @@ type User interface {
60
60
// GetField should optionally return a dynamic field
61
61
// based on its key. Useful for custom user fields.
62
62
// Keep in mind that these fields are encoded as a separate JSON key.
63
- GetField (key string ) (interface {} , error )
63
+ GetField (key string ) (any , error )
64
64
} /* Notes:
65
65
We could use a structure of User wrapper and separate interfaces for each of the methods
66
66
so they return ErrNotSupported if the implementation is missing it, so the `Features`
67
67
field and HasUserFeature can be omitted and
68
- add a Raw() interface{} to return the underline User implementation too.
68
+ add a Raw() any to return the underline User implementation too.
69
69
The advandages of the above idea is that we don't have to add new methods
70
70
for each of the builtin features and we can keep the (assumed) struct small.
71
71
But we dont as it has many disadvantages, unless is requested.
@@ -95,7 +95,7 @@ type SimpleUser struct {
95
95
var _ User = (* SimpleUser )(nil )
96
96
97
97
// GetRaw returns itself.
98
- func (u * SimpleUser ) GetRaw () (interface {} , error ) {
98
+ func (u * SimpleUser ) GetRaw () (any , error ) {
99
99
return u , nil
100
100
}
101
101
@@ -156,18 +156,18 @@ func (u *SimpleUser) GetToken() ([]byte, error) {
156
156
157
157
// GetField optionally returns a dynamic field from the `Fields` field
158
158
// based on its key.
159
- func (u * SimpleUser ) GetField (key string ) (interface {} , error ) {
159
+ func (u * SimpleUser ) GetField (key string ) (any , error ) {
160
160
if u .Fields == nil {
161
161
return nil , ErrNotSupported
162
162
}
163
163
164
164
return u .Fields [key ], nil
165
165
}
166
166
167
- // UserMap can be used to convert a common map[string]interface{} to a User.
167
+ // UserMap can be used to convert a common map[string]any to a User.
168
168
// Usage:
169
169
//
170
- // user := map[string]interface{} {
170
+ // user := map[string]any {
171
171
// "username": "kataras",
172
172
// "age" : 27,
173
173
// }
@@ -189,7 +189,7 @@ type UserMap Map
189
189
var _ User = UserMap {}
190
190
191
191
// GetRaw returns the underline map.
192
- func (u UserMap ) GetRaw () (interface {} , error ) {
192
+ func (u UserMap ) GetRaw () (any , error ) {
193
193
return Map (u ), nil
194
194
}
195
195
@@ -235,11 +235,11 @@ func (u UserMap) GetToken() ([]byte, error) {
235
235
236
236
// GetField returns the raw map's value based on its "key".
237
237
// It's not kind of useful here as you can just use the map.
238
- func (u UserMap ) GetField (key string ) (interface {} , error ) {
238
+ func (u UserMap ) GetField (key string ) (any , error ) {
239
239
return u [key ], nil
240
240
}
241
241
242
- func (u UserMap ) val (key string ) interface {} {
242
+ func (u UserMap ) val (key string ) any {
243
243
isTitle := unicode .IsTitle (rune (key [0 ])) // if starts with uppercase.
244
244
if isTitle {
245
245
key = strings .ToLower (key )
@@ -333,15 +333,15 @@ type (
333
333
}
334
334
335
335
userGetField interface {
336
- GetField (string ) interface {}
336
+ GetField (string ) any
337
337
}
338
338
339
339
// UserPartial is a User.
340
340
// It's a helper which wraps a struct value that
341
341
// may or may not complete the whole User interface.
342
342
// See Context.SetUser.
343
343
UserPartial struct {
344
- Raw interface {} `json:"raw"`
344
+ Raw any `json:"raw"`
345
345
userGetAuthorization `json:",omitempty"`
346
346
userGetAuthorizedAt `json:",omitempty"`
347
347
userGetID `json:",omitempty"`
@@ -356,7 +356,7 @@ type (
356
356
357
357
var _ User = (* UserPartial )(nil )
358
358
359
- func newUserPartial (i interface {} ) * UserPartial {
359
+ func newUserPartial (i any ) * UserPartial {
360
360
if i == nil {
361
361
return nil
362
362
}
@@ -407,7 +407,7 @@ func newUserPartial(i interface{}) *UserPartial {
407
407
}
408
408
409
409
// GetRaw returns the original raw instance of the user.
410
- func (u * UserPartial ) GetRaw () (interface {} , error ) {
410
+ func (u * UserPartial ) GetRaw () (any , error ) {
411
411
if u == nil {
412
412
return nil , ErrNotSupported
413
413
}
@@ -496,7 +496,7 @@ func (u *UserPartial) GetToken() ([]byte, error) {
496
496
// GetField should optionally return a dynamic field
497
497
// based on its key. Useful for custom user fields.
498
498
// Keep in mind that these fields are encoded as a separate JSON key.
499
- func (u * UserPartial ) GetField (key string ) (interface {} , error ) {
499
+ func (u * UserPartial ) GetField (key string ) (any , error ) {
500
500
if v := u .userGetField ; v != nil {
501
501
return v .GetField (key ), nil
502
502
}
0 commit comments