database

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package database provides access to covid data sources from the web.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is the database. The resources are lazy-loaded from 2 caches, either:

  1. in-memory, for the runtime;
  2. the file-system, as files saved in the specified directory.

If the cache period has expired, or the files don't exist already, the resources are taken from the web, and then stored in the caches.

func New

func New(origin, cachedir string, cacheExpiration time.Duration) *DB

New database. origin is the base URL common to all the resources (e.g. https://raw.githubusercontent.com/CSSEGISandData/COVID-1). cachedir is the full path of the directory where the resources are cached. cacheExpiration is the period after which the cache is refreshed (from endpoints under origin).

func (*DB) ActiveCases

func (db *DB) ActiveCases(country string, t time.Time) (int, error)

ActiveCases affected, selected by country and time.

func (*DB) Countries

func (db *DB) Countries() ([]string, error)

Countries listed in the resources, sorted by their name.

func (*DB) Latest

func (db *DB) Latest() (time.Time, error)

Latest update time.

func (*DB) Set

func (db *DB) Set(n EndpointName, endpoint string)

Set a new named endpoint to a web resource. The first resource that is set is considered the one with all cases, while the next resources are the ones with cases that can be subtracted from first one's cases to give active cases (DB.ActiveCases).

type EndpointName

type EndpointName string

EndpointName is a unique name identifying a web ednpoint and its related resource.

func (EndpointName) String

func (e EndpointName) String() string

Jump to

Keyboard shortcuts

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