apixu

package module
v0.0.0-...-2fe030c Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: MIT Imports: 5 Imported by: 0

README

apixu-go

GoDoc Build Status Go Report Card

Golang library for Apixu Weather API http://www.apixu.com

Installation

$ go get github.com/mohan3d/apixu-go

Usage

package main

import (
	"fmt"

	"github.com/mohan3d/apixu-go"
)

func main() {
	client := apixu.NewClient("<APIXU_KEY>")

	current, err := client.Current("Paris")

	if err != nil {
		panic(err)
	}

	fmt.Printf("%v °C, %v °F\n", current.Current.TempC, current.Current.TempF)

	forecast, err := client.Forecast("London", 3)

	if err != nil {
		panic(err)
	}

	fmt.Printf("%v\n", forecast.Location.Country)
}

Testing

APIXU_KEY must be exported to environment variables before running tests.

$ export APIXU_KEY=<YOUR_APIXU_KEY>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client describes apixu api client.

func NewClient

func NewClient(apiKey string) *Client

NewClient returns a new client reference.

func (*Client) Current

func (client *Client) Current(q string, optionalParams ...OptionalParam) (*CurrentWeather, error)

Current returns CurrentWeather obj representing current weather status.

func (*Client) Forecast

func (client *Client) Forecast(q string, days int, optionalParams ...OptionalParam) (*ForecastWeather, error)

Forecast returns ForecastWeather obj representing forecast status.

func (*Client) History

func (client *Client) History(q string, dt string, optionalParams ...OptionalParam) (*HistoryWeather, error)

History returns HistoryWeather obj representing history status.

func (*Client) Search

func (client *Client) Search(q string) (*MatchingCities, error)

Search returns MatchingCities obj representing a list of matched cities.

type Current

type Current struct {
	LastUpdatedEpoch int     `json:"last_updated_epoch"`
	LastUpdated      string  `json:"last_updated"`
	TempC            float64 `json:"temp_c"`
	TempF            float64 `json:"temp_f"`
	IsDay            int     `json:"is_day"`
	Condition        struct {
		Text string `json:"text"`
		Icon string `json:"icon"`
		Code int    `json:"code"`
	} `json:"condition"`
	WindMph    float64 `json:"wind_mph"`
	WindKph    float64 `json:"wind_kph"`
	WindDegree int     `json:"wind_degree"`
	WindDir    string  `json:"wind_dir"`
	PressureMb float64 `json:"pressure_mb"`
	PressureIn float64 `json:"pressure_in"`
	PrecipMm   float64 `json:"precip_mm"`
	PrecipIn   float64 `json:"precip_in"`
	Humidity   int     `json:"humidity"`
	Cloud      int     `json:"cloud"`
	FeelslikeC float64 `json:"feelslike_c"`
	FeelslikeF float64 `json:"feelslike_f"`
	VisKm      float64 `json:"vis_km"`
	VisMiles   float64 `json:"vis_miles"`
}

Current describes realtime weather information.

type CurrentWeather

type CurrentWeather struct {
	Location Location `json:"location"`
	Current  Current  `json:"current"`
}

CurrentWeather describes data returned by current.

type Forecast

type Forecast struct {
	Forecastday []struct {
		Date      string `json:"date"`
		DateEpoch int    `json:"date_epoch"`
		Day       struct {
			MaxtempC      float64 `json:"maxtemp_c"`
			MaxtempF      float64 `json:"maxtemp_f"`
			MintempC      float64 `json:"mintemp_c"`
			MintempF      float64 `json:"mintemp_f"`
			AvgtempC      float64 `json:"avgtemp_c"`
			AvgtempF      float64 `json:"avgtemp_f"`
			MaxwindMph    float64 `json:"maxwind_mph"`
			MaxwindKph    float64 `json:"maxwind_kph"`
			TotalprecipMm float64 `json:"totalprecip_mm"`
			TotalprecipIn float64 `json:"totalprecip_in"`
			AvgvisKm      float64 `json:"avgvis_km"`
			AvgvisMiles   float64 `json:"avgvis_miles"`
			Avghumidity   float64 `json:"avghumidity"`
			Condition     struct {
				Text string `json:"text"`
				Icon string `json:"icon"`
				Code int    `json:"code"`
			} `json:"condition"`
			Uv float64 `json:"uv"`
		} `json:"day"`
		Astro struct {
			Sunrise  string `json:"sunrise"`
			Sunset   string `json:"sunset"`
			Moonrise string `json:"moonrise"`
			Moonset  string `json:"moonset"`
		} `json:"astro"`
		Hour []struct {
			TimeEpoch int     `json:"time_epoch"`
			Time      string  `json:"time"`
			TempC     float64 `json:"temp_c"`
			TempF     float64 `json:"temp_f"`
			IsDay     int     `json:"is_day"`
			Condition struct {
				Text string `json:"text"`
				Icon string `json:"icon"`
				Code int    `json:"code"`
			} `json:"condition"`
			WindMph      float64 `json:"wind_mph"`
			WindKph      float64 `json:"wind_kph"`
			WindDegree   int     `json:"wind_degree"`
			WindDir      string  `json:"wind_dir"`
			PressureMb   float64 `json:"pressure_mb"`
			PressureIn   float64 `json:"pressure_in"`
			PrecipMm     float64 `json:"precip_mm"`
			PrecipIn     float64 `json:"precip_in"`
			Humidity     int     `json:"humidity"`
			Cloud        int     `json:"cloud"`
			FeelslikeC   float64 `json:"feelslike_c"`
			FeelslikeF   float64 `json:"feelslike_f"`
			WindchillC   float64 `json:"windchill_c"`
			WindchillF   float64 `json:"windchill_f"`
			HeatindexC   float64 `json:"heatindex_c"`
			HeatindexF   float64 `json:"heatindex_f"`
			DewpointC    float64 `json:"dewpoint_c"`
			DewpointF    float64 `json:"dewpoint_f"`
			WillItRain   int     `json:"will_it_rain"`
			ChanceOfRain string  `json:"chance_of_rain"`
			WillItSnow   int     `json:"will_it_snow"`
			ChanceOfSnow string  `json:"chance_of_snow"`
			VisKm        float64 `json:"vis_km"`
			VisMiles     float64 `json:"vis_miles"`
		} `json:"hour"`
	} `json:"forecastday"`
}

Forecast describes astronomy data.

type ForecastWeather

type ForecastWeather struct {
	Location Location `json:"location"`
	Current  Current  `json:"current"`
	Forecast Forecast `json:"forecast"`
}

ForecastWeather describes data returned by forecast.

type HistoryWeather

type HistoryWeather struct {
	Location Location `json:"location"`
	Forecast Forecast `json:"forecast"`
}

HistoryWeather describes data returned by history.

type Location

type Location struct {
	Name           string  `json:"name"`
	Region         string  `json:"region"`
	Country        string  `json:"country"`
	Lat            float64 `json:"lat"`
	Lon            float64 `json:"lon"`
	TzID           string  `json:"tz_id"`
	LocaltimeEpoch int     `json:"localtime_epoch"`
	Localtime      string  `json:"localtime"`
}

Location describes essential data of the matched location.

type MatchingCities

type MatchingCities []struct {
	ID      int     `json:"id"`
	Name    string  `json:"name"`
	Region  string  `json:"region"`
	Country string  `json:"country"`
	Lat     float64 `json:"lat"`
	Lon     float64 `json:"lon"`
	URL     string  `json:"url"`
}

MatchingCities describes data returned by search.

type OptionalParam

type OptionalParam struct {
	Name  string
	Value string
}

OptionalParam describes optional query parameters used in client methods.

Jump to

Keyboard shortcuts

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