From 91119b44c2acb05fb9e0d1eff6b54c959671638c Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Tue, 26 Jul 2022 23:37:38 -0400 Subject: [PATCH] Simplify getLocation --- server/current.go | 2 +- server/extended.go | 2 +- server/location.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/current.go b/server/current.go index 2cdd855..4aa7734 100644 --- a/server/current.go +++ b/server/current.go @@ -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") diff --git a/server/extended.go b/server/extended.go index d0f886b..c9ae4dd 100644 --- a/server/extended.go +++ b/server/extended.go @@ -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") diff --git a/server/location.go b/server/location.go index 7f7e5c3..468546e 100644 --- a/server/location.go +++ b/server/location.go @@ -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 {