Documentation ¶
Overview ¶
Package database provides an abstraction over getting and writing a database file.
Index ¶
Constants ¶
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.