2022-07-26 01:07:04 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
pb "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto"
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2022-07-26 03:52:33 -04:00
|
|
|
type Server struct {
|
2022-07-26 01:07:04 -04:00
|
|
|
pb.WeatherServiceServer
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
err := godotenv.Load()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
port, _ := strconv.Atoi(os.Getenv("PORT"))
|
|
|
|
|
|
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error starting server: %v\n", err)
|
|
|
|
} else {
|
|
|
|
log.Printf("Listening on port %d...\n", port)
|
|
|
|
}
|
|
|
|
|
|
|
|
s := grpc.NewServer()
|
2022-07-26 03:52:33 -04:00
|
|
|
pb.RegisterWeatherServiceServer(s, &Server{})
|
2022-07-26 01:07:04 -04:00
|
|
|
if err = s.Serve(lis); err != nil {
|
|
|
|
log.Fatalf("gRPC Server error: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|