go-corona: github.com/itsksaurabh/go-corona Index | Files

package gocorona

import "github.com/itsksaurabh/go-corona"

Package gocorona is a Golang client library for accessing global coronavirus (COVID-19, SARS-CoV-2) outbreak data. It consumes data from Coronavirus Tracker API.

You can read the API server documentation at https://github.com/ExpDev07/coronavirus-tracker-api.


create a new instance of Client, then use the various methods on the client to access different parts of the API. For demonstration:

  package main
  import (


  func main() {
  // client for accessing different endpoints of the API
	client := gocorona.Client{}
	ctx := context.Background()

  // GetLatestData returns total amonut confirmed cases, deaths, and recoveries.
	data, err := client.GetLatestData(ctx)
	if err != nil {
		log.Fatal("request failed:", err)

Notes: * Using the [https://godoc.org/context](https://godoc.org/context) package for passing context. * Look at tests(*_test.go) files for more sample usage.


Package Files

client.go doc.go latest.go locations.go


const (
    // DefaultBaseURL is the default server URL.
    DefaultBaseURL = "https://coronavirus-tracker-api.herokuapp.com/v2"

type CaseCountWithTimestamp Uses

type CaseCountWithTimestamp struct {
    Timestamp time.Time
    CaseCount int

CaseCountWithTimestamp holds timestamp with CaseCount

type Client Uses

type Client struct {
    // HTTPClient is a reusable http client instance.
    HTTP *http.Client
    // BaseURL is the REST endpoints URL of the api server
    BaseURL *url.URL

Client for accessing different endpoints of the API

func (Client) Do Uses

func (c Client) Do(req *http.Request, target interface{}) error

Do sends the http.Request and unmarshalls the JSON response into 'target'

func (Client) GetAllLocationData Uses

func (c Client) GetAllLocationData(ctx context.Context, timelines bool) (data Locations, err error)

GetAllLocationData returns all cases from all locations. You can Exclude/Include timelines. Timelines are excluded by default.

func (Client) GetDataByCountryCode Uses

func (c Client) GetDataByCountryCode(ctx context.Context, countryCode string, timelines bool) (data Locations, err error)

GetDataByCountryCode returns all cases from different locations of a country by it's Country Code. Check alpha-2 country codes here: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

func (Client) GetDataByLocationID Uses

func (c Client) GetDataByLocationID(ctx context.Context, id int, timelines bool) (data LocationData, err error)

GetDataByLocationID returns data of a specific location by it's ID. You can Exclude/Include timelines. Timelines are excluded by default. You can Exclude/Include timelines. Timelines are excluded by default.

func (Client) GetLatestData Uses

func (c Client) GetLatestData(ctx context.Context) (data LatestData, err error)

GetLatestData returns total amonut confirmed cases, deaths, and recoveries.

type Coordinates Uses

type Coordinates struct {
    Latitude  string `json:"latitude"`
    Longitude string `json:"longitude"`

Coordinates hols coordinates of a location

type ErrAPI Uses

type ErrAPI struct {
    // Response from the request which returned error.
    Response *http.Response

ErrAPI is returned by API calls when the response status code isn't 200.

func (ErrAPI) Error Uses

func (err ErrAPI) Error() (errStr string)

Error implements the error interface.

type Latest Uses

type Latest struct {
    Confirmed int `json:"confirmed"`
    Deaths    int `json:"deaths"`
    Recovered int `json:"recovered"`

Latest holds fields related to latest data

type LatestData Uses

type LatestData struct {
    Data Latest `json:"latest"`

LatestData holds response from the endpoint /v2/latest

type LatestWithTimeline Uses

type LatestWithTimeline struct {
    Latest   int      `json:"latest"`
    Timeline Timeline `json:"timeline"`

LatestWithTimeline struct holds latest count with timelines

func (*LatestWithTimeline) UnmarshalJSON Uses

func (t *LatestWithTimeline) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. coverts json keys from string to unix timestamp and it's values as case count.

type Location Uses

type Location struct {
    Coordinates Coordinates `json:"coordinates"`
    Country     string      `json:"country"`
    CountryCode string      `json:"country_code"`
    ID          int         `json:"id"`
    Latest      Latest      `json:"latest"`
    Province    string      `json:"province"`
    Timelines   Timelines   `json:"timelines,omitempty"`

Location holds data of a location

type LocationData Uses

type LocationData struct {
    Location Location `json:"location"`

LocationData holds data of a particular location

type Locations Uses

type Locations struct {
    Locations []Location `json:"locations"`

Locations holds response from endpoint /v2/locations

type Timeline Uses

type Timeline struct {
    Data []CaseCountWithTimestamp

Timeline holds list of Case Counts with timestamp

type Timelines Uses

type Timelines struct {
    Confirmed LatestWithTimeline `json:"confirmed"`
    Deaths    LatestWithTimeline `json:"deaths"`
    Recovered LatestWithTimeline `json:"recovered"`

Timelines holds latest data with timelines

Package gocorona imports 11 packages (graph). Updated 2020-05-23. Refresh now. Tools for package owners.