mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-07 04:09:15 +02:00
fix:#56 added update for grpc
This commit is contained in:
@@ -39,8 +39,15 @@ func main() {
|
||||
}
|
||||
|
||||
grpcClient := grpc.ConnectGRPCServer(host)
|
||||
|
||||
// Close the grpc connection when the main function ends
|
||||
defer grpc.CloseGRPCServer(grpcClient)
|
||||
|
||||
// Log the grpc connection
|
||||
// Test the connection to the grpc server
|
||||
grpcClient.Connect()
|
||||
slog.Info("GRPC connection state", "state", grpcClient.GetState())
|
||||
|
||||
// Initialize a new Fiber app
|
||||
webdavRequestMethods := []string{"PROPFIND", "MKCOL", "COPY", "MOVE"}
|
||||
|
||||
|
@@ -19,14 +19,31 @@ package grpc
|
||||
import (
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var conn *grpc.ClientConn
|
||||
var once sync.Once
|
||||
|
||||
func ConnectGRPCServer(host string) *grpc.ClientConn {
|
||||
conn, err := grpc.NewClient(host+":50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
slog.Error("could not connect to grpc server", "error", err)
|
||||
}
|
||||
once.Do(func() {
|
||||
var err error
|
||||
conn, err = grpc.NewClient(
|
||||
host+":50051",
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithKeepaliveParams(keepalive.ClientParameters{
|
||||
Time: 2 * time.Minute,
|
||||
Timeout: 20 * time.Second,
|
||||
PermitWithoutStream: true,
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
slog.Error("could not connect to grpc server", "error", err)
|
||||
}
|
||||
})
|
||||
return conn
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user