client

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package client provides a method to query an API endpoint to extract data about the latest covid numbers and report these to the cmd line via stdout or save them as a csv or markdown file

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorBadDateFormat = errors.New("Incorrect Date Format") //Bad date format from the command line
)

Functions

This section is empty.

Types

type APIClient

type APIClient struct {
	Client     *http.Client
	RequestURL string
}

APIClient the client and the request url for the api server

func NewClient

func NewClient(RequestURL string) *APIClient

NewClient returns a client for the user to query the api server

func (*APIClient) Get

func (c *APIClient) Get(country string, from, to time.Time, latest bool) (APIResponse, error)

Get the main get function which queries the server

type APIResponse

type APIResponse struct {
	Country    string   `json:"country"`
	Province   []string `json:"province"`
	RawData    RawData  `json:"timeline"`
	TimeSeries TimeSeries
}

APIResponse the main response from the server

func (*APIResponse) FormatResponse

func (r *APIResponse) FormatResponse(from, to time.Time, latest bool) error

FormatResponse format the timeseries map to something with more structure (i.e. []Day)

type Day

type Day struct {
	Country   string
	Date      time.Time
	Cases     int
	Deaths    int
	Recovered int
}

Day holds all the values for a given day

type RawData

type RawData struct {
	Cases     map[string]int `json:"cases"`
	Deaths    map[string]int `json:"deaths"`
	Recovered map[string]int `json:"recovered"`
}

RawData the raw response timeseries

type TimeSeries

type TimeSeries struct {
	Data []Day // A slice of daily data
}

TimeSeries holds a slice of days

func (*TimeSeries) Filter

func (ts *TimeSeries) Filter(from, to time.Time, latest bool)

Filter filter the time series data based on from, to or latest

func (*TimeSeries) Order

func (ts *TimeSeries) Order()

Order the data in chronological order

func (*TimeSeries) Print

func (ts *TimeSeries) Print(output io.Writer, format string)

Print print the timeseries data to an os.File

Jump to

Keyboard shortcuts

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