package entity import ( "strings" "time" ) const ( DeviceIOS = "ios" DeviceAndroid = "android" DeviceHarmony = "harmony" DeviceWindows = "windows" DeviceMacOS = "macos" DeviceWeb = "web" ) var deviceTypes = map[string]struct{}{ DeviceIOS: {}, DeviceAndroid: {}, DeviceHarmony: {}, DeviceWindows: {}, DeviceMacOS: {}, DeviceWeb: {}, } // UserDeviceLink is one user bound to one physical device (no app_id on this row). type UserDeviceLink struct { ID int64 UserID int64 DeviceID uint64 LastLoginAt time.Time LastActiveAt *time.Time CreatedAt time.Time } // LoginDevice is the device snapshot supplied at login. type LoginDevice struct { DeviceID uint64 AppID uint8 DeviceType string Platform string DeviceName string AppVersion string Language string RealIP string IDFV string AndroidID string } func NormalizeDeviceType(s string) string { return strings.ToLower(strings.TrimSpace(s)) } func ValidDeviceType(s string) bool { _, ok := deviceTypes[NormalizeDeviceType(s)] return ok } func DeviceTypeOf(d *LoginDevice) string { if d == nil { return "" } if t := NormalizeDeviceType(d.DeviceType); ValidDeviceType(t) { return t } return NormalizeDeviceType(d.Platform) }