coronavirus

package
v0.0.0-...-bb60f61 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package coronavirus contains utilities for obtaining UK coronavirus statistics.

Index

Constants

This section is empty.

Variables

View Source
var ErrStatus = errors.New("unexpected status code")

ErrStatus is the error given when an HTTP call to api.coronavirus.data.gov.uk returns an error status code.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Response   string `json:"response"`
	StatusCode int    `json:"status_code"`
	Status     string `json:"status"`
}

APIError represents the response format from the government coronavirus API when it returns an error.

func (APIError) Error

func (err APIError) Error() string

type Client

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

The Client type is used to communicate with the government coronavirus API.

func New

func New() (*Client, error)

New creates a new instance of the Client type.

func (*Client) GetSummary

func (cl *Client) GetSummary(ctx context.Context, date time.Time) (*Summary, error)

GetSummary returns a summary of coronavirus statistics for the provided date.

func (*Client) Ping

func (cl *Client) Ping() error

Ping returns a non-nil error if the API is deemed to be down.

type GetDataResponse

type GetDataResponse struct {
	Length       int `json:"length"`
	MaxPageLimit int `json:"maxPageLimit"`
	Data         []struct {
		Date      string `json:"date"`
		NewCases  int    `json:"newCases"`
		NewDeaths *int   `json:"newDeaths"` // This can be null, so we use a pointer.
	} `json:"data"`
	Pagination struct {
		Current  string      `json:"current"`
		Next     interface{} `json:"next"`
		Previous interface{} `json:"previous"`
		First    string      `json:"first"`
		Last     string      `json:"last"`
	} `json:"pagination"`
}

GetDataResponse represents the response format from the government coronavirus API.

type Summary

type Summary struct {
	Cases  float64
	Deaths float64
}

The Summary type contains all metrics for coronavirus data.

Jump to

Keyboard shortcuts

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