database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: ISC Imports: 19 Imported by: 0

Documentation

Overview

Package database provides MaxMind database management functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	LastUpdated time.Time `json:"last_updated"`
	Name        string    `json:"name"`
	Type        string    `json:"type"`
	Description string    `json:"description"`
	Path        string    `json:"-"`
	Size        int64     `json:"size"`
}

Info holds metadata about a database.

type Manager

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

Manager handles MMDB database lifecycle.

func New

func New() (*Manager, error)

New creates a new database manager.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the file watcher and clears the database maps. Readers are not explicitly closed to avoid races with active iterators; they will be garbage collected when no longer referenced.

func (*Manager) GetDatabase

func (m *Manager) GetDatabase(name string) (*Info, bool)

GetDatabase returns database info for the specified database by display name.

func (*Manager) GetReader

func (m *Manager) GetReader(name string) (*maxminddb.Reader, bool)

GetReader returns a reader for the specified database by display name.

func (*Manager) ListDatabases

func (m *Manager) ListDatabases() []*Info

ListDatabases returns all available databases.

func (*Manager) LoadDatabase

func (m *Manager) LoadDatabase(path string) error

LoadDatabase loads a single MMDB file.

func (*Manager) LoadDirectory

func (m *Manager) LoadDirectory(dir string) error

LoadDirectory scans a directory for MMDB files and loads them.

func (*Manager) RemoveDatabase

func (m *Manager) RemoveDatabase(name string)

RemoveDatabase removes a database by display name from the manager.

func (*Manager) RemoveDatabaseByPath

func (m *Manager) RemoveDatabaseByPath(path string)

RemoveDatabaseByPath removes a database by absolute path from the manager.

func (*Manager) StartWatching

func (m *Manager) StartWatching()

StartWatching starts the file watcher goroutine.

func (*Manager) WatchDirectory

func (m *Manager) WatchDirectory(dir string) error

WatchDirectory adds a directory to be watched for file changes.

type UpdateResult

type UpdateResult struct {
	LastUpdate time.Time `json:"last_update"`
	Database   string    `json:"database"`
	Error      string    `json:"error,omitempty"`
	Size       int64     `json:"size,omitempty"`
	Updated    bool      `json:"updated"`
}

UpdateResult represents the result of an update operation.

type Updater

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

Updater handles downloading and updating MaxMind databases.

func NewUpdater

func NewUpdater(cfg *config.Config, manager *Manager) (*Updater, error)

NewUpdater creates a new database updater.

func (*Updater) StartScheduledUpdates

func (u *Updater) StartScheduledUpdates(ctx context.Context)

StartScheduledUpdates starts a goroutine that periodically updates databases.

func (*Updater) UpdateAll

func (u *Updater) UpdateAll(ctx context.Context) ([]UpdateResult, error)

UpdateAll updates all configured databases.

func (*Updater) UpdateDatabase

func (u *Updater) UpdateDatabase(ctx context.Context, edition string) (UpdateResult, error)

UpdateDatabase updates a specific database.

Jump to

Keyboard shortcuts

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