You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
58 lines
1.3 KiB
2 years ago
|
package main
|
||
|
|
||
|
type WeatherAPI struct {
|
||
|
Coord Coord `json:"coord"`
|
||
|
Weather Weather `json:"weather`
|
||
|
Base string `json:"base"`
|
||
|
Main Main `json:"main"`
|
||
|
Visability string `json:"visibility"`
|
||
|
Wind Wind `json:"wind"`
|
||
|
Rain Rain `json:"rain"`
|
||
|
Clouds Cloud `json:"cloud"`
|
||
|
dt DT `json:"dt"`
|
||
|
Sys Sys `json:"sys"`
|
||
|
TimeZone int `json:"timezone"`
|
||
|
ID int `json:"id"`
|
||
|
Name string `json:"name"`
|
||
|
COD int `json:"cod"`
|
||
|
}
|
||
|
|
||
|
type Coord struct {
|
||
|
//etc
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
/*
|
||
|
//setting up openweathermap api
|
||
|
lat := "56.122970"
|
||
|
lon := "-3.932390"
|
||
|
city := "Stirling, uk"
|
||
|
api_key := "29e5139b86638988d333a28ba360bfd9"
|
||
|
full := "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=" + api_key + ""
|
||
|
fmt.Printf("\n------\nWeather url: %+s\n---------\n", full)
|
||
|
|
||
|
//read webpage
|
||
|
url := full
|
||
|
resp, err := http.Get(url)
|
||
|
//reads html as a slice of bytes
|
||
|
html, err := ioutil.ReadAll(resp.Body)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
*/
|
||
|
//print the html
|
||
|
//fmt.Printf("%s\n", html)
|
||
|
/*
|
||
|
out, _ := json.Marshal(html)
|
||
|
fmt.Printf("%s\n", out)
|
||
|
*/
|
||
|
/*
|
||
|
byteArray, error := json.MarshalIndent(html, "", " ")
|
||
|
if error != nil {
|
||
|
fmt.Println(err)
|
||
|
}
|
||
|
|
||
|
fmt.Println(string(byteArray))
|
||
|
*/
|
||
|
}
|