database

package
v4.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: Apache-2.0, MIT Imports: 17 Imported by: 11

Documentation

Overview

Package database provides an abstraction over getting and writing a database file.

Index

Constants

View Source
const ZeroMD5 = "00000000000000000000000000000000"

ZeroMD5 is the default value provided as an MD5 hash for a non-existent database.

Variables

This section is empty.

Functions

func CreateLockFile

func CreateLockFile(lockFilePath string, verbose bool) (*flock.Flock, error)

CreateLockFile takes the provided filePath and lockFilePath name to create a file lock. All output errors are wrapped in more detailed messages for debugging.

Types

type HTTPDatabaseReader

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

HTTPDatabaseReader is a Reader that uses an HTTP client to retrieve databases.

func (*HTTPDatabaseReader) Get

func (reader *HTTPDatabaseReader) Get(destination Writer, editionID string) error

Get retrieves the given edition ID using an HTTP client, writes it to the Writer, and validates the hash before committing.

type LocalFileDatabaseWriter

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

LocalFileDatabaseWriter is a database.Writer that stores the database to the local file system.

func NewLocalFileDatabaseWriter

func NewLocalFileDatabaseWriter(filePath, lockFilePath string, verbose bool) (*LocalFileDatabaseWriter, error)

NewLocalFileDatabaseWriter create a LocalFileDatabaseWriter. It creates the necessary lock and temporary files to protect the database from concurrent writes.

func (*LocalFileDatabaseWriter) Close

func (writer *LocalFileDatabaseWriter) Close() error

Close closes the temporary file and releases the file lock.

func (*LocalFileDatabaseWriter) Commit

func (writer *LocalFileDatabaseWriter) Commit() error

Commit renames the temporary file to the name of the database file and syncs the directory.

func (*LocalFileDatabaseWriter) GetHash

func (writer *LocalFileDatabaseWriter) GetHash() string

GetHash returns the hash of the current database file.

func (*LocalFileDatabaseWriter) SetFileModificationTime

func (writer *LocalFileDatabaseWriter) SetFileModificationTime(lastModified time.Time) error

SetFileModificationTime sets the database's file access and modified times to the given time.

func (*LocalFileDatabaseWriter) ValidHash

func (writer *LocalFileDatabaseWriter) ValidHash(expectedHash string) error

ValidHash checks that the temporary file's MD5 matches the given hash.

func (*LocalFileDatabaseWriter) Write

func (writer *LocalFileDatabaseWriter) Write(p []byte) (int, error)

Write writes to the temporary file.

type Reader

type Reader interface {
	Get(destination Writer, editionID string) error
}

Reader provides an interface for retrieving a database update and copying it into place.

func NewHTTPDatabaseReader

func NewHTTPDatabaseReader(client *http.Client, config *geoipupdate.Config) Reader

NewHTTPDatabaseReader creates a Reader that downloads database updates via HTTP.

type Writer

type Writer interface {
	io.WriteCloser
	ValidHash(expectedHash string) error
	GetHash() string
	SetFileModificationTime(lastModified time.Time) error
	Commit() error
}

Writer provides an interface for writing a database to a target location.

Jump to

Keyboard shortcuts

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