@@ -34,7 +34,7 @@ var ErrNotSupported = errors.New("not supported")
3434// - UserPartial (a wrapper by SetUser)
3535type User interface {
3636 // GetRaw should return the raw instance of the user, if supported.
37- GetRaw () (interface {} , error )
37+ GetRaw () (any , error )
3838 // GetAuthorization should return the authorization method,
3939 // e.g. Basic Authentication.
4040 GetAuthorization () (string , error )
@@ -60,12 +60,12 @@ type User interface {
6060 // GetField should optionally return a dynamic field
6161 // based on its key. Useful for custom user fields.
6262 // 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 )
6464} /* Notes:
6565We could use a structure of User wrapper and separate interfaces for each of the methods
6666so they return ErrNotSupported if the implementation is missing it, so the `Features`
6767field 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.
6969The advandages of the above idea is that we don't have to add new methods
7070for each of the builtin features and we can keep the (assumed) struct small.
7171But we dont as it has many disadvantages, unless is requested.
@@ -95,7 +95,7 @@ type SimpleUser struct {
9595var _ User = (* SimpleUser )(nil )
9696
9797// GetRaw returns itself.
98- func (u * SimpleUser ) GetRaw () (interface {} , error ) {
98+ func (u * SimpleUser ) GetRaw () (any , error ) {
9999 return u , nil
100100}
101101
@@ -156,18 +156,18 @@ func (u *SimpleUser) GetToken() ([]byte, error) {
156156
157157// GetField optionally returns a dynamic field from the `Fields` field
158158// based on its key.
159- func (u * SimpleUser ) GetField (key string ) (interface {} , error ) {
159+ func (u * SimpleUser ) GetField (key string ) (any , error ) {
160160 if u .Fields == nil {
161161 return nil , ErrNotSupported
162162 }
163163
164164 return u .Fields [key ], nil
165165}
166166
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.
168168// Usage:
169169//
170- // user := map[string]interface{} {
170+ // user := map[string]any {
171171// "username": "kataras",
172172// "age" : 27,
173173// }
@@ -189,7 +189,7 @@ type UserMap Map
189189var _ User = UserMap {}
190190
191191// GetRaw returns the underline map.
192- func (u UserMap ) GetRaw () (interface {} , error ) {
192+ func (u UserMap ) GetRaw () (any , error ) {
193193 return Map (u ), nil
194194}
195195
@@ -235,11 +235,11 @@ func (u UserMap) GetToken() ([]byte, error) {
235235
236236// GetField returns the raw map's value based on its "key".
237237// 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 ) {
239239 return u [key ], nil
240240}
241241
242- func (u UserMap ) val (key string ) interface {} {
242+ func (u UserMap ) val (key string ) any {
243243 isTitle := unicode .IsTitle (rune (key [0 ])) // if starts with uppercase.
244244 if isTitle {
245245 key = strings .ToLower (key )
@@ -333,15 +333,15 @@ type (
333333 }
334334
335335 userGetField interface {
336- GetField (string ) interface {}
336+ GetField (string ) any
337337 }
338338
339339 // UserPartial is a User.
340340 // It's a helper which wraps a struct value that
341341 // may or may not complete the whole User interface.
342342 // See Context.SetUser.
343343 UserPartial struct {
344- Raw interface {} `json:"raw"`
344+ Raw any `json:"raw"`
345345 userGetAuthorization `json:",omitempty"`
346346 userGetAuthorizedAt `json:",omitempty"`
347347 userGetID `json:",omitempty"`
@@ -356,7 +356,7 @@ type (
356356
357357var _ User = (* UserPartial )(nil )
358358
359- func newUserPartial (i interface {} ) * UserPartial {
359+ func newUserPartial (i any ) * UserPartial {
360360 if i == nil {
361361 return nil
362362 }
@@ -407,7 +407,7 @@ func newUserPartial(i interface{}) *UserPartial {
407407}
408408
409409// GetRaw returns the original raw instance of the user.
410- func (u * UserPartial ) GetRaw () (interface {} , error ) {
410+ func (u * UserPartial ) GetRaw () (any , error ) {
411411 if u == nil {
412412 return nil , ErrNotSupported
413413 }
@@ -496,7 +496,7 @@ func (u *UserPartial) GetToken() ([]byte, error) {
496496// GetField should optionally return a dynamic field
497497// based on its key. Useful for custom user fields.
498498// 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 ) {
500500 if v := u .userGetField ; v != nil {
501501 return v .GetField (key ), nil
502502 }
0 commit comments