2024-09-13 15:31:40 +01:00
|
|
|
package auth
|
2024-02-08 01:16:14 +00:00
|
|
|
|
2024-10-05 21:08:02 +01:00
|
|
|
import "github.com/hardfinhq/go-date"
|
|
|
|
|
2024-02-08 01:16:14 +00:00
|
|
|
type UserInfoFields map[string]any
|
|
|
|
|
|
|
|
func (u UserInfoFields) GetString(key string) (string, bool) {
|
|
|
|
s, ok := u[key].(string)
|
|
|
|
return s, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u UserInfoFields) GetStringOrDefault(key, other string) string {
|
2024-02-10 11:59:45 +00:00
|
|
|
s, ok := u[key].(string)
|
2024-02-08 01:16:14 +00:00
|
|
|
if !ok {
|
|
|
|
s = other
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2024-02-10 11:59:45 +00:00
|
|
|
func (u UserInfoFields) GetStringOrEmpty(key string) string {
|
|
|
|
s, _ := u[key].(string)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2024-10-05 21:08:02 +01:00
|
|
|
func (u UserInfoFields) GetStringFromKeysOrEmpty(keys ...string) string {
|
|
|
|
for _, key := range keys {
|
|
|
|
s, _ := u[key].(string)
|
|
|
|
if s == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2024-02-08 01:16:14 +00:00
|
|
|
func (u UserInfoFields) GetBoolean(key string) (bool, bool) {
|
|
|
|
b, ok := u[key].(bool)
|
|
|
|
return b, ok
|
|
|
|
}
|
2024-10-05 21:08:02 +01:00
|
|
|
|
|
|
|
func (u UserInfoFields) GetNullDate(key string) date.NullDate {
|
|
|
|
s, _ := u[key].(string)
|
|
|
|
fromStr, err := date.FromString(s)
|
|
|
|
return date.NullDate{Date: fromStr, Valid: err == nil}
|
|
|
|
}
|