statsstore

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

README

Stats Store

Open in Gitpod

Tests Status Go Report Card PkgGoDev

Stats Store - a visitor stats storage implementation for Go.

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). You can find a copy of the license at https://www.gnu.org/licenses/agpl-3.0.en.html

For commercial use, please use my contact page to obtain a commercial license.

Installation

go get -u github.com/dracory/statsstore

Setup

store, err := NewStore(NewStoreOptions{
	VisitorTableName:     "stats_visitor",
	DB:                 databaseInstance,
	AutomigrateEnabled: true,
})

Documentation

Index

Constants

View Source
const (
	COLUMN_ID                   = "id"
	COLUMN_COUNTRY              = "country"
	COLUMN_CREATED_AT           = "created_at"
	COLUMN_SOFT_DELETED_AT      = "soft_deleted_at"
	COLUMN_IP_ADDRESS           = "ip_address"
	COLUMN_PATH                 = "path"
	COLUMN_UPDATED_AT           = "updated_at"
	COLUMN_FINGERPRINT          = "fingerprint"
	COLUMN_USER_AGENT           = "user_agent"
	COLUMN_USER_ACCEPT_LANGUAGE = "user_accept_language"
	COLUMN_USER_ACCEPT_ENCODING = "user_accept_encoding"
	COLUMN_USER_BROWSER         = "user_browser"
	COLUMN_USER_BROWSER_VERSION = "user_browser_version"
	COLUMN_USER_DEVICE          = "user_device"
	COLUMN_USER_DEVICE_TYPE     = "user_device_type"
	COLUMN_USER_OS              = "user_os"
	COLUMN_USER_OS_VERSION      = "user_os_version"
	COLUMN_USER_REFERRER        = "user_referrer"
)
View Source
const MAX_DATETIME = "9999-12-31 23:59:59"

MAX_DATETIME is a far-future datetime used as the default soft-delete sentinel.

Variables

This section is empty.

Functions

This section is empty.

Types

type NewStoreOptions

type NewStoreOptions struct {
	VisitorTableName   string
	DB                 *sql.DB
	AutomigrateEnabled bool
	DebugEnabled       bool
}

NewStoreOptions defines the options for creating a new stats store.

type StoreInterface

type StoreInterface interface {
	// MigrateDown drops the stats store tables
	MigrateDown(ctx context.Context, tx ...*sql.Tx) error

	// MigrateUp creates the stats store tables
	MigrateUp(ctx context.Context, tx ...*sql.Tx) error

	EnableDebug(debug bool)
	GetDB() *sql.DB

	VisitorCount(ctx context.Context, query VisitorQueryInterface) (int64, error)
	VisitorCreate(ctx context.Context, user VisitorInterface) error
	VisitorDelete(ctx context.Context, user VisitorInterface) error
	VisitorDeleteByID(ctx context.Context, id string) error
	VisitorFindByID(ctx context.Context, userID string) (VisitorInterface, error)
	VisitorList(ctx context.Context, query VisitorQueryInterface) ([]VisitorInterface, error)
	VisitorRegister(ctx context.Context, r *http.Request) error
	VisitorSoftDelete(ctx context.Context, user VisitorInterface) error
	VisitorSoftDeleteByID(ctx context.Context, id string) error
	VisitorUpdate(ctx context.Context, user VisitorInterface) error
}

StoreInterface defines the interface for a stats store.

func NewStore

func NewStore(opts NewStoreOptions) (StoreInterface, error)

NewStore creates a new stats store.

type VisitorInterface

type VisitorInterface interface {
	// Methods
	FingerprintCalculate() string
	IsSoftDeleted() bool

	GetID() string
	SetID(id string) VisitorInterface

	GetPath() string
	SetPath(path string) VisitorInterface

	GetCountry() string
	SetCountry(country string) VisitorInterface

	GetCreatedAt() string
	GetCreatedAtCarbon() *carbon.Carbon
	SetCreatedAt(createdAt string) VisitorInterface

	GetSoftDeletedAt() string
	GetSoftDeletedAtCarbon() *carbon.Carbon
	SetSoftDeletedAt(deletedAt string) VisitorInterface

	GetFingerprint() string
	SetFingerprint(fingerprint string) VisitorInterface

	GetIpAddress() string
	SetIpAddress(ipAddress string) VisitorInterface

	GetUpdatedAt() string
	GetUpdatedAtCarbon() *carbon.Carbon
	SetUpdatedAt(updatedAt string) VisitorInterface

	GetUserAcceptLanguage() string
	SetUserAcceptLanguage(userAcceptLanguage string) VisitorInterface

	GetUserAcceptEncoding() string
	SetUserAcceptEncoding(userAcceptEncoding string) VisitorInterface

	GetUserAgent() string
	SetUserAgent(userAgent string) VisitorInterface

	GetUserBrowser() string
	SetUserBrowser(userBrowser string) VisitorInterface

	GetUserBrowserVersion() string
	SetUserBrowserVersion(userBrowserVersion string) VisitorInterface

	GetUserDevice() string
	SetUserDevice(userDevice string) VisitorInterface

	GetUserDeviceType() string
	SetUserDeviceType(userDeviceType string) VisitorInterface

	GetUserOs() string
	SetUserOs(userOs string) VisitorInterface

	GetUserOsVersion() string
	SetUserOsVersion(userOsVersion string) VisitorInterface

	GetUserReferrer() string
	SetUserReferrer(userReferrer string) VisitorInterface
}

VisitorInterface defines the interface for a visitor record.

func NewVisitor

func NewVisitor() VisitorInterface

NewVisitor creates a new visitor.

func NewVisitorFromExistingData

func NewVisitorFromExistingData(data map[string]string) VisitorInterface

NewVisitorFromExistingData creates a new visitor from a raw column map.

type VisitorQueryInterface added in v1.1.0

type VisitorQueryInterface interface {
	Validate() error

	HasCountry() bool
	Country() string
	SetCountry(country string) VisitorQueryInterface

	HasCreatedAtGte() bool
	CreatedAtGte() string
	SetCreatedAtGte(createdAtGte string) VisitorQueryInterface

	HasCreatedAtLte() bool
	CreatedAtLte() string
	SetCreatedAtLte(createdAtLte string) VisitorQueryInterface

	HasDeviceType() bool
	DeviceType() string
	SetDeviceType(deviceType string) VisitorQueryInterface

	HasDistinct() bool
	Distinct() string
	SetDistinct(distinct string) VisitorQueryInterface

	HasID() bool
	ID() string
	SetID(id string) VisitorQueryInterface

	HasIDIn() bool
	IDIn() []string
	SetIDIn(idIn []string) VisitorQueryInterface

	HasLimit() bool
	Limit() int
	SetLimit(limit int) VisitorQueryInterface

	HasOffset() bool
	Offset() int
	SetOffset(offset int) VisitorQueryInterface

	HasOrderBy() bool
	OrderBy() string
	SetOrderBy(orderBy string) VisitorQueryInterface

	HasPathContains() bool
	PathContains() string
	SetPathContains(pathContains string) VisitorQueryInterface

	HasPathExact() bool
	PathExact() string
	SetPathExact(pathExact string) VisitorQueryInterface

	HasSortOrder() bool
	SortOrder() string
	SetSortOrder(sortOrder string) VisitorQueryInterface

	HasSoftDeletedIncluded() bool
	SoftDeletedIncluded() bool
	SetSoftDeletedIncluded(withSoftDeleted bool) VisitorQueryInterface
}

VisitorQueryInterface defines the interface for visitor query operations.

func NewVisitorQuery added in v1.1.0

func NewVisitorQuery() VisitorQueryInterface

NewVisitorQuery creates a new visitor query.

func VisitorQuery added in v1.1.0

func VisitorQuery() VisitorQueryInterface

VisitorQuery is a shortcut for NewVisitorQuery.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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