Files
ocis/ocis-pkg/checks/checkgrpc.go
Christian Richter fd262970b3 simplify code
Signed-off-by: Christian Richter <crichter@owncloud.com>
2024-10-24 11:16:25 +02:00

28 lines
642 B
Go

package checks
import (
"context"
"fmt"
"github.com/owncloud/ocis/v2/ocis-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
}
}