database

package
v0.0.0-...-7402fb7 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB wraps the sql.DB connection

func New

func New(dbPath string) (*DB, error)

New creates a new database connection and initializes the schema

func (*DB) CleanupOldLogs

func (db *DB) CleanupOldLogs(retentionDays int) (int64, error)

CleanupOldLogs deletes logs older than retentionDays and returns the number deleted If retentionDays is 0, no cleanup is performed

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection

func (*DB) GetAllLogs

func (db *DB) GetAllLogs() ([]RequestLog, error)

GetAllLogs retrieves all request logs from the database with a safety limit

func (*DB) GetEndpointStats

func (db *DB) GetEndpointStats() ([]EndpointStats, error)

GetEndpointStats retrieves statistics grouped by endpoint/URL

func (*DB) GetLogs

func (db *DB) GetLogs(limit int) ([]RequestLog, error)

GetLogs retrieves request logs with optional limit

func (*DB) GetSourceStats

func (db *DB) GetSourceStats() ([]SourceStats, error)

GetSourceStats retrieves statistics grouped by IP address

func (*DB) GetSummary

func (db *DB) GetSummary() (*Summary, error)

GetSummary retrieves overall statistics

func (*DB) LogRequest

func (db *DB) LogRequest(ipAddress, url string) error

LogRequest logs an HTTP request to the database with retry logic

func (*DB) Ping

func (db *DB) Ping() error

Ping checks if the database connection is alive

type EndpointStats

type EndpointStats struct {
	URL       string    `json:"url"`
	Count     int64     `json:"count"`
	FirstSeen time.Time `json:"first_seen"`
	LastSeen  time.Time `json:"last_seen"`
	UniqueIPs int64     `json:"unique_ips"`
}

EndpointStats represents statistics for a specific endpoint

type RequestLog

type RequestLog struct {
	ID        int64
	IPAddress string
	URL       string
	Timestamp time.Time
}

RequestLog represents a logged HTTP request

type SourceStats

type SourceStats struct {
	IPAddress  string    `json:"ip_address"`
	Count      int64     `json:"count"`
	FirstSeen  time.Time `json:"first_seen"`
	LastSeen   time.Time `json:"last_seen"`
	UniqueURLs int64     `json:"unique_urls"`
}

SourceStats represents statistics for a specific IP address

type Summary

type Summary struct {
	TotalRequests int64     `json:"total_requests"`
	UniqueIPs     int64     `json:"unique_ips"`
	UniqueURLs    int64     `json:"unique_urls"`
	FirstRequest  time.Time `json:"first_request"`
	LastRequest   time.Time `json:"last_request"`
}

Summary represents overall statistics

Jump to

Keyboard shortcuts

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