database

package
v6.0.0-...-75421ee Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: Apache-2.0, MIT Imports: 18 Imported by: 0

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

This section is empty.

Types

type HTTPReader

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

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

func (*HTTPReader) Read

func (r *HTTPReader) Read(ctx context.Context, editionID, hash string) (*ReadResult, error)

Read attempts to fetch database updates for a specific editionID. It takes an editionID and it's previously downloaded hash if available as arguments and returns a ReadResult struct as a response. It's the responsibility of the Writer to close the io.ReadCloser included in the response after consumption.

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(result *ReadResult) error

Write writes the result struct returned by a Reader to a database file.

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"`
	// contains filtered or unexported fields
}

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.

func NewHTTPReader

func NewHTTPReader(
	proxy *url.URL,
	path string,
	accountID int,
	licenseKey string,
	retryFor time.Duration,
	verbose bool,
) Reader

NewHTTPReader creates a Reader that downloads database updates via HTTP.

type Writer

type Writer interface {
	Write(*ReadResult) 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