cwb

package
v0.0.0-...-441d2fb Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Data set Ids
	// 36 hour weather forecasts
	F36HW = "F-C0032-001"

	// Townships forecasts
	FTW2DayYilanCounty      = "F-D0047-001"
	FTW7DayYilanCounty      = "F-D0047-003"
	FTW2DayTaoyuanCity      = "F-D0047-005"
	FTW7DayTaoyuanCity      = "F-D0047-007"
	FTW2DayHsinchuCounty    = "F-D0047-009"
	FTW7DayHsinchuCounty    = "F-D0047-011"
	FTW2DayMiaoliCounty     = "F-D0047-013"
	FTW7DayMiaoliCounty     = "F-D0047-015"
	FTW2DayChanghuaCounty   = "F-D0047-017"
	FTW7DayChanghuaCounty   = "F-D0047-019"
	FTW2DayNantouCounty     = "F-D0047-021"
	FTW7DayNantouCounty     = "F-D0047-023"
	FTW2DayYunlinCounty     = "F-D0047-025"
	FTW7DayYunlinCounty     = "F-D0047-027"
	FTW2DayChiayiCounty     = "F-D0047-029"
	FTW7DayChiayiCounty     = "F-D0047-031"
	FTW2DayPingtungCounty   = "F-D0047-033"
	FTW7DayPingtungCounty   = "F-D0047-035"
	FTW2DayTaitungCounty    = "F-D0047-037"
	FTW7DayTaitungCounty    = "F-D0047-039"
	FTW2DayHualienCounty    = "F-D0047-041"
	FTW7DayHualienCounty    = "F-D0047-043"
	FTW2DayPenghuCounty     = "F-D0047-045"
	FTW7DayPenghuCounty     = "F-D0047-047"
	FTW2DayKeelungCity      = "F-D0047-049"
	FTW7DayKeelungCity      = "F-D0047-051"
	FTW2DayHsinchuCity      = "F-D0047-053"
	FTW7DayHsinchuCity      = "F-D0047-055"
	FTW2DayChiayiCity       = "F-D0047-057"
	FTW7DayChiayiCity       = "F-D0047-059"
	FTW2DayTaipeiCity       = "F-D0047-061"
	FTW7DayTaipeiCity       = "F-D0047-063"
	FTW2DayKaohsiungCity    = "F-D0047-065"
	FTW7DayKaohsiungCity    = "F-D0047-067"
	FTW2DayNewTaipeiCity    = "F-D0047-069"
	FTW7DayNewTaipeiCity    = "F-D0047-071"
	FTW2DayTaichungCity     = "F-D0047-073"
	FTW7DayTaichungCity     = "F-D0047-075"
	FTW2DayTainanCity       = "F-D0047-077"
	FTW7DayTainanCity       = "F-D0047-079"
	FTW2DayLienchiangCounty = "F-D0047-081"
	FTW7DayLienchiangCounty = "F-D0047-083"
	FTW2DayKinmenCounty     = "F-D0047-085"
	FTW7DayKinmenCounty     = "F-D0047-087"

	FTW2DayTaiwan = "F-D0047-089"
	FTW7DayTaiwan = "F-D0047-091"

	FTWTaiwan = "F-D0047-093"
)
View Source
const (
	// Data set Ids
	// Weather observation data
	StationObsWeatherId = "O-A0001-001"

	// Rainfall observation data
	StationObsRainfallId = "O-A0002-001"
)
View Source
const (
	// tide forecasts 1 month
	Tide1MonthId = "F-A0021-001"
)

Variables

View Source
var (
	ErrElementNotFound = errors.New("element not found")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string

	// Services
	Dataset       *DatasetService
	Forecasts     *ForecastsService
	StationObs    *StationObsService
	TideForecasts *TideForecastsService
	// contains filtered or unexported fields
}

A Client manages communication with the CWB API.

func NewClient

func NewClient(token string, httpClient *http.Client) *Client

NewClient returns a new CWB API client. The token are required for authentication. If a nil httpClient is provided, http.DefaultClient will be used.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request, and returns the API response.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string, v interface{}) (*http.Response, error)

Get method make a GET HTTP request.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)

NewRequest creates an API request.

type Data

type Data struct {
	CwbCategory              string `json:"cwbCategory"`
	Datanamefixid            string `json:"datanamefixid"`
	Title                    string `json:"title"`
	Description              string `json:"description"`
	FieldDescription         string `json:"fieldDescription"`
	Type                     string `json:"type"`
	License                  string `json:"license"`
	LicenseURL               string `json:"licenseURL"`
	Cost                     string `json:"cost"`
	CostURL                  string `json:"costURL"`
	CostLaw                  string `json:"costLaw"`
	Organization             string `json:"organization"`
	OrganizationContactName  string `json:"organizationContactName"`
	OrganizationContactPhone string `json:"organizationContactPhone"`
	OrganizationContactEmail string `json:"organizationContactEmail"`
	Publisher                string `json:"publisher"`
	PublisherContactName     string `json:"publisherContactName"`
	PublisherContactPhone    string `json:"publisherContactPhone"`
	PublisherContactEmail    string `json:"publisherContactEmail"`
	AccrualPeriodicity       string `json:"accrualPeriodicity"`
	TemporalCoverageFrom     string `json:"temporalCoverageFrom,omitempty"`
	TemporalCoverageTo       string `json:"temporalCoverageTo,omitempty"`
	Issued                   string `json:"issued"`
	Modified                 string `json:"modified"`
	Spatial                  string `json:"spatial"`
	Language                 string `json:"language"`
	LandingPage              string `json:"landingPage"`
	Notes                    string `json:"notes"`
}

type DataSet

type DataSet struct {
	Name string
	Type DataSetType
}

type DataSetType

type DataSetType int
const (
	DataSetTypeFTW DataSetType = iota
	DataSetTypeFTW7Day
)

type Dataset

type Dataset struct {
	Dataid []string `json:"dataid"`
}

type DatasetService

type DatasetService service

func (*DatasetService) GetData

func (s *DatasetService) GetData(ctx context.Context, id string) (*Data, *http.Response, error)

func (*DatasetService) GetIds

func (s *DatasetService) GetIds(ctx context.Context) (*Dataset, *http.Response, error)

type ErrorResponse

type ErrorResponse struct {
	*http.Response
	Message string
}

ErrorResponse reports error caused by an API request.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type F36HWCountryLocation

type F36HWCountryLocation struct {
	LocationName   string `json:"locationName"`
	WeatherElement []struct {
		ElementName string `json:"elementName"`
		Time        []struct {
			StartTime string `json:"startTime"`
			EndTime   string `json:"endTime"`
			Parameter struct {
				ParameterName  string  `json:"parameterName"`
				ParameterValue *string `json:"parameterValue,omitempty"`
				ParameterUnit  *string `json:"parameterUnit,omitempty"`
			} `json:"parameter"`
		} `json:"time"`
	} `json:"weatherElement"`
}

type F36HWTime

type F36HWTime struct {
	StartTime string    `json:"startTime"`
	EndTime   string    `json:"endTime"`
	Parameter Parameter `json:"parameter"`
}

type FTWCountryLocation

type FTWCountryLocation struct {
	DatasetDescription string               `json:"datasetDescription"`
	LocationsName      *string              `json:"locationsName,omitempty"`
	Dataid             string               `json:"dataid"`
	Location           []FTWDatasetLocation `json:"location"`
}

type FTWDatasetLocation

type FTWDatasetLocation struct {
	LocationName   string              `json:"locationName"`
	Geocode        string              `json:"geocode"`
	Lat            string              `json:"lat"`
	Lon            string              `json:"lon"`
	WeatherElement []FTWWeatherElement `json:"weatherElement"`
}

type FTWElementValue

type FTWElementValue struct {
	Value    string `json:"value"`
	Measures string `json:"measures"`
}

type FTWTime

type FTWTime struct {
	DataTime     *string           `json:"dataTime,omitempty"`
	StartTime    *string           `json:"startTime,omitempty"`
	EndTime      *string           `json:"endTime,omitempty"`
	ElementValue []FTWElementValue `json:"elementValue,omitempty"`
	Parameter    []Parameter       `json:"parameter,omitempty"`
}

type FTWWeatherElement

type FTWWeatherElement struct {
	Description    *string   `json:"description,omitempty"`
	ElementName    string    `json:"elementName"`
	ElementMeasure *string   `json:"elementMeasure,omitempty"`
	Time           []FTWTime `json:"time"`
}

type Fields

type Fields struct {
	Id   string `json:"id"`
	Type string `json:"type"`
}

type Forecast36HourWeather

type Forecast36HourWeather struct {
	Success string `json:"success"`
	Result  Result `json:"result"`
	Records struct {
		DatasetDescription string                 `json:"datasetDescription"`
		Location           []F36HWCountryLocation `json:"location"`
	} `json:"records"`
}

type ForecastTownshipsWeather

type ForecastTownshipsWeather struct {
	Success string `json:"success"`
	Result  Result `json:"result"`
	Records struct {
		Locations []FTWCountryLocation `json:"locations"`
	} `json:"records"`
}

type ForecastsService

type ForecastsService service

func (*ForecastsService) Get36HourWeather

func (s *ForecastsService) Get36HourWeather(ctx context.Context, locationNames, elements []string) (*Forecast36HourWeather, *http.Response, error)

Get36HourWeather gets 36-hour weather forecasts.

func (*ForecastsService) GetTownshipsWeatherByDataId

func (s *ForecastsService) GetTownshipsWeatherByDataId(ctx context.Context, dataId string, locationNames, elements []string) (*ForecastTownshipsWeather, *http.Response, error)

GetTownshipsWeatherByDataId gets townships forecasts by data Id. See http://opendata.cwb.gov.tw/datalist for dataId (F-D0047-001 - F-D0047-091).

func (*ForecastsService) GetTownshipsWeatherByLocations

func (s *ForecastsService) GetTownshipsWeatherByLocations(ctx context.Context, locationIds, locationNames, elements []string) (*ForecastTownshipsWeather, *http.Response, error)

GetTownshipsWeatherByLocations gets townships forecasts by locationIds and locationNames.

type Location

type Location struct {
	Name    string
	DataSet []DataSet
}

func FindLocationByName

func FindLocationByName(name string) (Location, error)

type Parameter

type Parameter struct {
	ParameterName  string  `json:"parameterName"`
	ParameterValue *string `json:"parameterValue,omitempty"`
	ParameterUnit  *string `json:"parameterUnit,omitempty"`
}

type Result

type Result struct {
	ResourceId *string  `json:"resource_id,omitempty"`
	Fields     []Fields `json:"fields"`
}

type StationObsElement

type StationObsElement struct {
	ElementName  string `json:"elementName"`
	ElementValue string `json:"elementValue"`
}

type StationObsElements

type StationObsElements []StationObsElement

func (StationObsElements) GetByName

func (es StationObsElements) GetByName(name string) (StationObsElement, error)

type StationObsLocation

type StationObsLocation struct {
	Lat          string `json:"lat"`
	Lon          string `json:"lon"`
	LocationName string `json:"locationName"`
	StationId    string `json:"stationId"`
	Time         struct {
		ObsTime string `json:"obsTime"`
	} `json:"time"`
	WeatherElement StationObsElements `json:"weatherElement"`
	Parameter      []Parameter        `json:"parameter"`
}

type StationObsRainfall

type StationObsRainfall StationObsResponse

type StationObsResponse

type StationObsResponse struct {
	Success string `json:"success"`
	Result  Result `json:"result"`
	Records struct {
		Location []StationObsLocation `json:"location"`
	} `json:"records"`
}

type StationObsService

type StationObsService service

func (*StationObsService) GetRainfall

func (s *StationObsService) GetRainfall(ctx context.Context, options url.Values) (*StationObsRainfall, *http.Response, error)

GetRainfall gets rainfall observation data.

func (*StationObsService) GetWeather

func (s *StationObsService) GetWeather(ctx context.Context, options url.Values) (*StationObsWeather, *http.Response, error)

GetWeather gets weather observation data.

type StationObsWeather

type StationObsWeather StationObsResponse

type TideForecast1MonthOptions

type TideForecast1MonthOptions struct {
	Limit        int    `url:"limit,omitempty"`
	Offset       int    `url:"offset,omitempty"`
	LocationName string `url:"locationName,omitempty"` // see https://opendata.cwb.gov.tw/opendatadoc/MMC/A0021-001.pdf
	ElementName  string `url:"elementName,omitempty"`
	Sort         string `url:"sort,omitempty"`
	StartTime    string `url:"startTime,omitempty"`
	DataTime     string `url:"dataTime,omitempty"`
	TimeForm     string `url:"timeForm,omitempty"`
	TimeTo       string `url:"timeTo,omitempty"`
}

type TideForecast1MonthResponse

type TideForecast1MonthResponse struct {
	Success string `json:"success"`
	Result  Result `json:"result"`
	Records struct {
		Dataid   string                 `json:"dataid"`
		Note     string                 `json:"note"`
		Location []TideForecastLocation `json:"location"`
	} `json:"records"`
}

type TideForecastLocation

type TideForecastLocation struct {
	LocationName string `json:"locationName"`
	StationId    string `json:"stationId"`
	ValidTime    []struct {
		StartTime      string                       `json:"startTime"`
		EndTime        string                       `json:"endTime"`
		WeatherElement []TideForecastWeatherElement `json:"weatherElement"`
	} `json:"validTime"`
}

type TideForecastParameter

type TideForecastParameter struct {
	ParameterName    string  `json:"parameterName"`
	ParameterValue   *string `json:"parameterValue,omitempty"`
	ParameterMeasure *string `json:"parameterMeasure,omitempty"`
}

type TideForecastTime

type TideForecastTime struct {
	DataTime  string                  `json:"dataTime"`
	Parameter []TideForecastParameter `json:"parameter"`
}

type TideForecastWeatherElement

type TideForecastWeatherElement struct {
	ElementName  string             `json:"elementName"`
	ElementValue *string            `json:"elementValue,omitempty"`
	Time         []TideForecastTime `json:"time,omitempty"`
}

type TideForecastsService

type TideForecastsService service

Jump to

Keyboard shortcuts

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