mirror of
https://codeberg.org/andyscott/OpenWeather-gRPC-API.git
synced 2025-01-04 14:05:54 -05:00
Hard coded units for now, minor formatting updates
This commit is contained in:
parent
6b89ae295b
commit
1cef0eba5a
3 changed files with 6 additions and 7 deletions
|
@ -16,7 +16,7 @@ func getCurrent(in *pb.RequestCurrent) string {
|
||||||
url := "https://pro.openweathermap.org/data/2.5/weather?q="
|
url := "https://pro.openweathermap.org/data/2.5/weather?q="
|
||||||
token := "&appid=" + os.Getenv("API_KEY")
|
token := "&appid=" + os.Getenv("API_KEY")
|
||||||
|
|
||||||
url = url + city + token
|
url = url + city + "&units=imperial" + token
|
||||||
|
|
||||||
res, err := http.Get(url)
|
res, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -28,12 +28,10 @@ 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)
|
return string(body)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *server) Current(ctx context.Context, in *pb.RequestCurrent) (*pb.SendCurrent, error) {
|
func (s *Server) Current(ctx context.Context, in *pb.RequestCurrent) (*pb.SendCurrent, error) {
|
||||||
log.Println("'Current' function called...")
|
log.Println("'Current' function called...")
|
||||||
|
|
||||||
return &pb.SendCurrent{
|
return &pb.SendCurrent{
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type server struct {
|
type Server struct {
|
||||||
pb.WeatherServiceServer
|
pb.WeatherServiceServer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
s := grpc.NewServer()
|
s := grpc.NewServer()
|
||||||
pb.RegisterWeatherServiceServer(s, &server{})
|
pb.RegisterWeatherServiceServer(s, &Server{})
|
||||||
if err = s.Serve(lis); err != nil {
|
if err = s.Serve(lis); err != nil {
|
||||||
log.Fatalf("gRPC Server error: %v\n", err)
|
log.Fatalf("gRPC Server error: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,6 @@ func main() {
|
||||||
|
|
||||||
c := pb.NewWeatherServiceClient(conn)
|
c := pb.NewWeatherServiceClient(conn)
|
||||||
|
|
||||||
doCurrent(c)
|
//doCurrent(c)
|
||||||
|
doExtended(c)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue