Skip to content
go-corona is a Golang client library for accessing global coronavirus (COVID-19, SARS-CoV-2) outbreak data.
Go
Branch: master
Clone or download

Latest commit

Latest commit 0d05e5d Mar 31, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Add .circleci/config.yml Mar 21, 2020
assets add logo Mar 20, 2020
testdata add new generated testdata Mar 31, 2020
LICENSE Initial commit Mar 20, 2020
README.md Update README.md Mar 31, 2020
client.go export Do() Mar 31, 2020
client_test.go add comments Mar 31, 2020
doc.go fix lint error Mar 22, 2020
go.mod add go mod files Mar 21, 2020
go.sum add go mod files Mar 21, 2020
latest.go refactor latest.go : use makeGetRequest() Mar 27, 2020
latest_test.go change http client to test client Mar 21, 2020
locations.go refactor locations.go : use makeGetRequest() Mar 27, 2020
locations_test.go change http client to testClient Mar 21, 2020
magefile.go magefile : Mar 31, 2020

README.md

go-corona

itsksaurabh Go Report Card GoDoc Built with Mage MIT License

go-corona is a Golang client library for accessing global coronavirus (COVID-19, SARS-CoV-2) outbreak data.

API Documentation

It consumes data from Coronavirus Tracker API. You can read the API server documentation here.

Available data sources:

Installation

Make sure you have set the environment variable $GOPATH

export GOPATH="path/to/your/go/folder"

Obtain the latest version of the go-corona library with:

go get github.com/itsksaurabh/go-corona

Then, add the following to your Golang project:

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

Usage

Package provides a client for accessing different endpoints of the 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 (
	"context"
	"fmt"
	"log"
	
	"github.com/itsksaurabh/go-corona"
)

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)
	}
	fmt.Println(data)
}

Notes:

Error Handling

All errors generated at runtime will be returned to the calling client method. Any API request for which the API returns an error encoded in a JSON response will be parsed and returned by the client method as a Golang error struct. Lastly, it is important to note that for HTTP requests, if the response code returned is not '200 OK', an error will be returned to the client method detailing the response code that was received.

Testing

In order to run the tests for this library, you will first need to install Mage - A Make/rake-like dev tool using Go. You can install the dependency with the following command:

Using GOPATH

go get -u -d github.com/magefile/mage
cd $GOPATH/src/github.com/magefile/mage
go run bootstrap.go

Using Go Modules

git clone https://github.com/magefile/mage
cd mage
go run bootstrap.go

The mage binary will be created in your $GOPATH/bin directory. You may also install a binary release from Mage's releases page.

Then run all tests by executing the following in your command line:

$ mage -v Test

Updating Test Data

You can update the test data inside ./testdata/ directory by enabling the -update flag while testing. By default the flag is set to false.

Or

simply Run the following command to update all test data :

$ mage generate

Contributing

I welcome pull requests, bug fixes and issue reports. Before proposing a change, please discuss your change by raising an issue.

Maintainer

Kumar Saurabh

License

MIT © Kumar Saurabh

Logo Attributions

The project Logo is made using the Go gopher designed by Renee French and the Gopher sticker made by Takuya Ueda. The Go Logo is copyrighted by the Go authors. All of the logo materials are licensed under the Creative Commons 3.0 Attributions license.

You can’t perform that action at this time.