finish the grpc listen
This commit is contained in:
parent
dbdff6b477
commit
29135938c2
@ -1,9 +1,14 @@
|
||||
package api
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"logger/data"
|
||||
"logger/logs"
|
||||
"net"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type LogServer struct {
|
||||
@ -32,3 +37,20 @@ func (l *LogServer) WriteLog(
|
||||
res := &logs.LogResponse{Result: "logged!"}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ func main() {
|
||||
|
||||
go app.rpcListen()
|
||||
|
||||
go app.gRPCListen()
|
||||
|
||||
// start web server
|
||||
log.Println("Starting service on port", webPort)
|
||||
app.serve()
|
||||
|
Loading…
Reference in New Issue
Block a user