client

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: 14 Imported by: 0

Documentation

Overview

Package client is a client for downloading GeoIP2 and GeoLite2 MMDB databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client downloads GeoIP2 and GeoLite2 MMDB databases.

After creation, it is valid for concurrent use.

func New

func New(
	accountID int,
	licenseKey string,
	options ...Option,
) (Client, error)

New creates a Client.

func (Client) Download

func (c Client) Download(
	ctx context.Context,
	editionID,
	md5 string,
) (DownloadResponse, error)

Download attempts to download the edition.

The editionID parameter is a valid database edition ID, such as "GeoIP2-City".

The MD5 parameter is a string representation of the MD5 sum of the database MMDB file you have previously downloaded. If you don't yet have one downloaded, this can be "". This is used to know if an update is available and avoid consuming resources if there is not.

If the current MD5 checksum matches what the server currently has, no download is performed.

type DownloadResponse

type DownloadResponse struct {
	// LastModified is the date that the database was last modified. It will
	// only be set if UpdateAvailable is true.
	LastModified time.Time

	// MD5 is the string representation of the new database. It will only be set
	// if UpdateAvailable is true.
	MD5 string

	// Reader can be read to access the database itself. It will only contain a
	// database if UpdateAvailable is true.
	//
	// If the Download call does not return an error, Reader will always be
	// non-nil.
	//
	// If UpdateAvailable is true, the caller must read Reader to completion and
	// close it.
	Reader io.ReadCloser

	// UpdateAvailable is true if there is an update available for download. It
	// will be false if the MD5 used in the Download call matches what the server
	// currently has.
	UpdateAvailable bool
}

DownloadResponse describes the result of a Download call.

type Option

type Option func(*Client)

Option is an option for configuring Client.

func WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint sets the base endpoint to use. By default we use https://updates.maxmind.com.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the HTTP client to use. By default we use http.DefaultClient.

Jump to

Keyboard shortcuts

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