database

package
v7.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0, MIT Imports: 13 Imported by: 0

Documentation

Overview

Package database writes MMDBs to disk.

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

This section is empty.

Types

type LocalFileWriter

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

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

func NewLocalFileWriter

func NewLocalFileWriter(
	databaseDir string,
	preserveFileTime bool,
	verbose bool,
) (*LocalFileWriter, error)

NewLocalFileWriter create a LocalFileWriter.

func (*LocalFileWriter) GetHash

func (w *LocalFileWriter) GetHash(editionID string) (string, error)

GetHash returns the hash of the current database file.

func (*LocalFileWriter) Write

func (w *LocalFileWriter) Write(
	editionID string,
	reader io.ReadCloser,
	newMD5 string,
	lastModified time.Time,
) (err error)

Write writes the database to a file. The database content will be read from reader.

type ReadResult

type ReadResult struct {
	EditionID  string    `json:"edition_id"`
	OldHash    string    `json:"old_hash"`
	NewHash    string    `json:"new_hash"`
	ModifiedAt time.Time `json:"modified_at"`
	CheckedAt  time.Time `json:"checked_at"`
}

ReadResult is the struct returned by a Reader's Get method.

func (ReadResult) MarshalJSON

func (r ReadResult) MarshalJSON() ([]byte, error)

MarshalJSON is a custom json marshaler that strips out zero time fields.

func (*ReadResult) UnmarshalJSON

func (r *ReadResult) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom json unmarshaler that converts timestamps to go time fields.

type Reader

type Reader interface {
	Read(context.Context, string, string) (*ReadResult, error)
}

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

type Writer

type Writer interface {
	Write(string, io.ReadCloser, string, time.Time) error
	GetHash(editionID string) (string, 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