Help us shape the future of Go! Take the 2026 Go Developer Survey

device

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package device defines the device tracking domain entity and its store interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseUserAgent

func ParseUserAgent(ua string) (browser, os, deviceType string)

ParseUserAgent extracts browser, OS, and device type from a User-Agent string. Uses simple heuristic parsing to avoid external dependencies.

Types

type Device

type Device struct {
	ID           id.DeviceID      `json:"id"`
	UserID       id.UserID        `json:"user_id"`
	AppID        id.AppID         `json:"app_id"`
	EnvID        id.EnvironmentID `json:"env_id"`
	Name         string           `json:"name,omitempty"`
	Type         string           `json:"type,omitempty"`
	Browser      string           `json:"browser,omitempty"`
	OS           string           `json:"os,omitempty"`
	IPAddress    string           `json:"ip_address,omitempty"`
	Fingerprint  string           `json:"fingerprint,omitempty"`
	Trusted      bool             `json:"trusted"`
	TrustedUntil *time.Time       `json:"trusted_until,omitempty"`
	LastSeenAt   time.Time        `json:"last_seen_at"`
	CreatedAt    time.Time        `json:"created_at"`
	UpdatedAt    time.Time        `json:"updated_at"`
}

Device represents a tracked user device.

type Store

type Store interface {
	CreateDevice(ctx context.Context, d *Device) error
	GetDevice(ctx context.Context, deviceID id.DeviceID) (*Device, error)
	GetDeviceByFingerprint(ctx context.Context, userID id.UserID, fingerprint string) (*Device, error)
	UpdateDevice(ctx context.Context, d *Device) error
	DeleteDevice(ctx context.Context, deviceID id.DeviceID) error
	ListUserDevices(ctx context.Context, userID id.UserID) ([]*Device, error)
	// ListDevices returns the most recent devices across all users, up to limit.
	ListDevices(ctx context.Context, limit int) ([]*Device, error)
}

Store defines the persistence interface for device tracking operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL