Documentation ¶
Overview ¶
Package database provides an abstraction over getting and writing a database file.
Index ¶
- Constants
- func CreateLockFile(lockFilePath string, verbose bool) (*flock.Flock, error)
- type HTTPDatabaseReader
- type LocalFileDatabaseWriter
- func (writer *LocalFileDatabaseWriter) Close() error
- func (writer *LocalFileDatabaseWriter) Commit() error
- func (writer *LocalFileDatabaseWriter) GetHash() string
- func (writer *LocalFileDatabaseWriter) SetFileModificationTime(lastModified time.Time) error
- func (writer *LocalFileDatabaseWriter) ValidHash(expectedHash string) error
- func (writer *LocalFileDatabaseWriter) Write(p []byte) (int, error)
- type Reader
- type Writer
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 ¶
Types ¶
type HTTPDatabaseReader ¶
type HTTPDatabaseReader struct {
// contains filtered or unexported fields
}
HTTPDatabaseReader is a Reader that uses an HTTP client to retrieve databases.
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.
type Reader ¶
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.