model

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EVENT_ACTIVE = "_active" // 用户活跃事件
)

内置事件类型常量

Variables

This section is empty.

Functions

func CreateEvent

func CreateEvent(db *gorm.DB, eventName string, metadata map[string]interface{}, appID, userID string) error

CreateEvent 创建事件记录

func GenFingerprint

func GenFingerprint(appID, errType, message string) string

GenFingerprint 生成错误指纹 规则:MD5(appId + type + message)

func GetDB

func GetDB() *gorm.DB

GetDB 获取数据库实例

func GetEventCount

func GetEventCount(db *gorm.DB, appID string, eventName string, since time.Time) (int64, error)

GetEventCount 获取事件总数

func GetUniqueUserCount

func GetUniqueUserCount(db *gorm.DB, appID string, eventName string, since time.Time) (int64, error)

GetUniqueUserCount 获取唯一用户数(UV)

func InitDB

func InitDB(path string) (*gorm.DB, error)

InitDB 初始化数据库(SQLite + 性能优化)

Types

type DailyEvent

type DailyEvent struct {
	Date  string `json:"date"`
	Count int64  `json:"count"`
}

DailyEvent 每日事件统计

func GetDailyEvents

func GetDailyEvents(db *gorm.DB, appID string, eventName string, days int) ([]DailyEvent, error)

GetDailyEvents 获取每日事件统计

type ErrorLog

type ErrorLog struct {
	ID          uint   `gorm:"primaryKey"`
	Fingerprint string `gorm:"uniqueIndex"` // 去重查询
	Type        string `gorm:"index"`       // 按类型筛选
	Message     string
	Stack       string
	URL         string
	AppID       string `gorm:"index"` // 按应用筛选
	UserAgent   string
	Count       int `gorm:"default:1"`
	FirstSeen   time.Time
	LastSeen    time.Time `gorm:"index"` // 按最近出现排序
}

ErrorLog 错误日志

type Event

type Event struct {
	ID        uint            `gorm:"primaryKey"`
	EventName string          `gorm:"index:idx_event_name;index:idx_app_event_time"` // 事件名称
	Metadata  json.RawMessage `gorm:"type:text"`                                     // 元数据(JSON 格式)
	AppID     string          `gorm:"index:idx_app_event_time"`                      // 应用 ID
	UserID    string          `gorm:"index"`                                         // 用户 ID
	CreatedAt time.Time       `gorm:"index:idx_app_event_time"`                      // 创建时间
}

Event 统一事件模型

type EventDetail

type EventDetail struct {
	ID        uint            `json:"id"`
	EventName string          `json:"eventName"`
	Metadata  json.RawMessage `json:"metadata"`
	AppID     string          `json:"appId"`
	UserID    string          `json:"userId"`
	CreatedAt time.Time       `json:"createdAt"`
}

EventDetail 事件详情

func GetEventList

func GetEventList(db *gorm.DB, appID string, eventName string, page int, pageSize int) ([]EventDetail, int64, error)

GetEventList 获取事件列表(分页)

type EventStats

type EventStats struct {
	EventName string `json:"eventName"`
	Count     int64  `json:"count"`
}

EventStats 事件统计结果

func GetEventStats

func GetEventStats(db *gorm.DB, appID string, eventName string, days int) ([]EventStats, error)

GetEventStats 获取事件统计(按事件名称分组)

type EventStatsSummary

type EventStatsSummary struct {
	TotalCount int64 `json:"totalCount"`
	TodayCount int64 `json:"todayCount"`
	UV         int64 `json:"uv"`
}

EventStatsSummary 事件统计摘要

func GetEventStatsSummary

func GetEventStatsSummary(db *gorm.DB, appID string, eventName string, days int) (*EventStatsSummary, error)

GetEventStatsSummary 获取事件统计摘要

type TopEvent

type TopEvent struct {
	EventName string `json:"eventName"`
	Count     int64  `json:"count"`
}

TopEvent Top 事件结果

func GetTopEvents

func GetTopEvents(db *gorm.DB, appID string, days int, limit int) ([]TopEvent, error)

GetTopEvents 获取 Top 事件排行

Jump to

Keyboard shortcuts

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