finish the grpc listen

This commit is contained in:
vinchent 2024-09-06 22:42:23 +02:00
parent dbdff6b477
commit 29135938c2
2 changed files with 25 additions and 1 deletions

View File

@ -1,9 +1,14 @@
package api package main
import ( import (
"context" "context"
"fmt"
"log"
"logger/data" "logger/data"
"logger/logs" "logger/logs"
"net"
"google.golang.org/grpc"
) )
type LogServer struct { type LogServer struct {
@ -32,3 +37,20 @@ func (l *LogServer) WriteLog(
res := &logs.LogResponse{Result: "logged!"} res := &logs.LogResponse{Result: "logged!"}
return res, nil return res, nil
} }
func (app *Config) gRPCListen() {
lis, err := net.Listen("tcp", fmt.Sprintf(":%s", gRpcPort))
if err != nil {
log.Fatalf("Failed to listen to gRPC %v", err)
}
s := grpc.NewServer()
logs.RegisterLogServiceServer(s, &LogServer{Models: app.Models})
log.Printf("gRPC Server started on port %s", gRpcPort)
if err := s.Serve(lis); err != nil {
log.Fatalf("Failed to listen to gRPC %v", err)
}
}

View File

@ -59,6 +59,8 @@ func main() {
go app.rpcListen() go app.rpcListen()
go app.gRPCListen()
// start web server // start web server
log.Println("Starting service on port", webPort) log.Println("Starting service on port", webPort)
app.serve() app.serve()