mirror of
https://codeberg.org/andyscott/OpenWeather-gRPC-API.git
synced 2024-12-20 12:03:10 -05:00
Simplify getLocation
This commit is contained in:
parent
af88be6ef1
commit
91119b44c2
3 changed files with 4 additions and 4 deletions
|
@ -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")
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue