analytics

package
v0.0.0-...-2be9cac Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type AnalyticsBackgroundService

type AnalyticsBackgroundService struct {
	// contains filtered or unexported fields
}

func NewAnalyticsBackgroundService

func NewAnalyticsBackgroundService(analytics ViewsService, log *zap.SugaredLogger, lc fx.Lifecycle) *AnalyticsBackgroundService

func (*AnalyticsBackgroundService) Start

func (s *AnalyticsBackgroundService) Start()

func (*AnalyticsBackgroundService) Stop

func (s *AnalyticsBackgroundService) Stop()

type AnalyticsPeriod

type AnalyticsPeriod int32
const ANALYTICS_PERIOD_TOTAL AnalyticsPeriod = 0

type AnalyticsPeriods

type AnalyticsPeriods struct {
	Hour  AnalyticsPeriod
	Day   AnalyticsPeriod
	Week  AnalyticsPeriod
	Month AnalyticsPeriod
	Year  AnalyticsPeriod
}

func CurrentAnalyticsPeriods

func CurrentAnalyticsPeriods(now time.Time) AnalyticsPeriods

type BookViewEntry

type BookViewEntry struct {
	BookID int64
	Views  int64
}

type Counters

type Counters interface {
	Namespace(name string) CountersNamespace
}

func NewAnalyticsCounters

func NewAnalyticsCounters(redisClient *redis.Client, log *zap.SugaredLogger) Counters

type CountersNamespace

type CountersNamespace interface {
	Incr(ctx context.Context, key, uniqueId string, incrBy int64, expire time.Duration) error
	Get(ctx context.Context, key string) (int64, error)
	Delete(ctx context.Context, key string) error
	PullPendingCounters(ctx context.Context, delete bool) (map[string]int64, error)
}

type RedisCounters

type RedisCounters struct {
	// contains filtered or unexported fields
}

func (*RedisCounters) Namespace

func (c *RedisCounters) Namespace(name string) CountersNamespace

type ViewMetadata

type ViewMetadata struct {
	UserID uuid.NullUUID
	IP     net.IP
}

func (ViewMetadata) UniqueID

func (m ViewMetadata) UniqueID() string

type Views

type Views struct {
	Total int64
	Year  int64
	Month int64
	Week  int64
	Day   int64
	Hour  int64
}

type ViewsService

type ViewsService interface {
	IncrBookView(ctx context.Context, bookID int64, meta ViewMetadata) error
	IncrChapterView(ctx context.Context, bookID, chapterID int64, meta ViewMetadata) error
	GetBookViews(ctx context.Context, bookID int64) (Views, error)
	GetMostViewedBooks(ctx context.Context, period AnalyticsPeriod) ([]BookViewEntry, error)
	CommitPendingViewsToDB(ctx context.Context)
}

func NewAnalyticsViewsService

func NewAnalyticsViewsService(db store.DBTX, counters Counters, log *zap.SugaredLogger) ViewsService

Jump to

Keyboard shortcuts

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