Fix string format

This commit is contained in:
Archie Fox
2025-03-26 22:29:46 +03:00
parent f162a3300d
commit 67b53cd4c4
3 changed files with 51 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
package weather
import (
"demo/weather/geo"
"fmt"
"io"
"net/http"
"net/url"
)
func GetWeather(geo geo.GeoData, format int) string {
baseUrl, err := url.Parse("https://wttr.in/" + geo.City)
if err != nil {
fmt.Println(err.Error())
return ""
}
params := url.Values{}
params.Add("format", fmt.Sprint(format))
baseUrl.RawQuery = params.Encode()
resp, err := http.Get(baseUrl.String())
if err != nil {
fmt.Println(err.Error())
return ""
}
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println(err.Error())
return ""
}
return string(body)
}