Simplify getLocation

This commit is contained in:
Andrew Scott 2022-07-26 23:37:38 -04:00
parent af88be6ef1
commit 91119b44c2
Signed by: a
GPG key ID: 3EB62D0BBB8DB381
3 changed files with 4 additions and 4 deletions

View file

@ -17,7 +17,7 @@ func (s *Server) Current(ctx context.Context, in *pb.RequestCurrent) (*pb.SendCu
log.Println("'Current' function called...")
url := "https://pro.openweathermap.org/data/2.5/weather?"
lat, lon := getLocation(in, in.City)
lat, lon := getLocation(in.City)
units := "&units=imperial"
token := "&appid=" + os.Getenv("API_KEY")

View file

@ -17,7 +17,7 @@ func (s *Server) Extended(ctx context.Context, in *pb.RequestExtended) (*pb.Send
log.Println("'Extended' function called...")
url := "https://api.openweathermap.org/data/2.5/forecast/daily?"
lat, lon := getLocation(in, in.City)
lat, lon := getLocation(in.City)
days := "&cnt=" + fmt.Sprint(in.Days)
units := "&units=imperial"
token := "&appid=" + os.Getenv("API_KEY")

View file

@ -53,12 +53,12 @@ func (s *Server) Location(ctx context.Context, in *pb.RequestLocation) (*pb.Send
// Used internally to fetch precise locations for Current and Extended
// Receives gRPC requests (interface) and the location (string)
// Returns the latitude (float32) and longitude (float32) for a given location
func getLocation(msg interface{}, loc string) (float32, float32) {
func getLocation(city string) (float32, float32) {
url := "http://api.openweathermap.org/geo/1.0/direct?q="
token := "&appid=" + os.Getenv("API_KEY")
url = url + loc + token
url = url + city + token
res, err := http.Get(url)
if err != nil {