mirror of
https://codeberg.org/andyscott/OpenWeather-gRPC-API.git
synced 2024-12-21 12:13:09 -05:00
Simplified code for Current and Extended
This commit is contained in:
parent
4296dbc43c
commit
971489f4ad
2 changed files with 8 additions and 16 deletions
|
@ -10,10 +10,11 @@ import (
|
||||||
pb "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto"
|
pb "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getCurrent(in *pb.RequestCurrent) string {
|
func (s *Server) Current(ctx context.Context, in *pb.RequestCurrent) (*pb.SendCurrent, error) {
|
||||||
|
log.Println("'Current' function called...")
|
||||||
|
|
||||||
city := in.City
|
|
||||||
url := "https://pro.openweathermap.org/data/2.5/weather?q="
|
url := "https://pro.openweathermap.org/data/2.5/weather?q="
|
||||||
|
city := in.City
|
||||||
token := "&appid=" + os.Getenv("API_KEY")
|
token := "&appid=" + os.Getenv("API_KEY")
|
||||||
|
|
||||||
url = url + city + "&units=imperial" + token
|
url = url + city + "&units=imperial" + token
|
||||||
|
@ -28,13 +29,8 @@ func getCurrent(in *pb.RequestCurrent) string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading weather response: %v", err)
|
log.Printf("Error reading weather response: %v", err)
|
||||||
}
|
}
|
||||||
return string(body)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) Current(ctx context.Context, in *pb.RequestCurrent) (*pb.SendCurrent, error) {
|
|
||||||
log.Println("'Current' function called...")
|
|
||||||
|
|
||||||
return &pb.SendCurrent{
|
return &pb.SendCurrent{
|
||||||
Payload: getCurrent(in),
|
Payload: string(body),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,12 @@ import (
|
||||||
pb "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto"
|
pb "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getExtended(in *pb.RequestExtended) string {
|
func (s *Server) Extended(ctx context.Context, in *pb.RequestExtended) (*pb.SendExtended, error) {
|
||||||
|
log.Println("'Extended' function called...")
|
||||||
|
|
||||||
|
url := "https://api.openweathermap.org/data/2.5/forecast/daily?q="
|
||||||
city := in.City
|
city := in.City
|
||||||
days := "&cnt=" + fmt.Sprint(in.Days)
|
days := "&cnt=" + fmt.Sprint(in.Days)
|
||||||
url := "https://api.openweathermap.org/data/2.5/forecast/daily?q="
|
|
||||||
token := "&appid=" + os.Getenv("API_KEY")
|
token := "&appid=" + os.Getenv("API_KEY")
|
||||||
|
|
||||||
url = url + city + "&units=imperial" + days + token
|
url = url + city + "&units=imperial" + days + token
|
||||||
|
@ -30,13 +31,8 @@ func getExtended(in *pb.RequestExtended) string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading extending weather: %v\n", err)
|
log.Printf("Error reading extending weather: %v\n", err)
|
||||||
}
|
}
|
||||||
return string(body)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) Extended(ctx context.Context, in *pb.RequestExtended) (*pb.SendExtended, error) {
|
|
||||||
log.Println("'Extended' function called...")
|
|
||||||
|
|
||||||
return &pb.SendExtended{
|
return &pb.SendExtended{
|
||||||
Payload: getExtended(in),
|
Payload: string(body),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue