Files
opencloud/pkg/checks/checkgrpc.go
Jörn Friedrich Dreyer b07b5a1149 use plain pkg module
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
2025-01-13 16:42:19 +01:00

28 lines
643 B
Go

package checks
import (
"context"
"fmt"
"github.com/opencloud-eu/opencloud/pkg/handlers"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
// NewGRPCCheck checks the reachability of a grpc server.
func NewGRPCCheck(address string) func(context.Context) error {
return func(_ context.Context) error {
address, err := handlers.FailSaveAddress(address)
if err != nil {
return err
}
conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("could not connect to grpc server: %v", err)
}
_ = conn.Close()
return nil
}
}