Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cmd/healthcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"context"
"fmt"

"github.com/crazy-max/diun/v4/pb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

// HealthcheckCmd holds healthcheck command
type HealthcheckerCmd struct {
Test HealthcheckCmd `cmd:"" help:"Run a healthcheck."`
}

// HealthcheckCmd holds healthcheck test command
type HealthcheckCmd struct {
GRPCAuthority string `name:"grpc-authority" default:"127.0.0.1:42286" help:"Link to Diun gRPC server."`
}

func (s *HealthcheckCmd) Run(_ *Context) error {
conn, err := grpc.NewClient(s.GRPCAuthority, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return err
}
defer conn.Close()

healthcheckSvc := pb.NewHealthcheckServiceClient(conn)

nt, err := healthcheckSvc.Healthcheck(context.Background(), &pb.HealthcheckRequest{})
if err != nil {
return err
}

fmt.Println(nt.Message)
return nil
}
9 changes: 5 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import (
var (
version = "dev"
cli struct {
Version kong.VersionFlag `name:"version" help:"Print version information."`
Serve ServeCmd `cmd:"" help:"Starts Diun server."`
Image ImageCmd `cmd:"" help:"Manage image manifests."`
Notif NotifCmd `cmd:"" help:"Manage notifications."`
Version kong.VersionFlag `name:"version" help:"Print version information."`
Serve ServeCmd `cmd:"" help:"Starts Diun server."`
Image ImageCmd `cmd:"" help:"Manage image manifests."`
Notif NotifCmd `cmd:"" help:"Manage notifications."`
Healthcheck HealthcheckerCmd `cmd:"" help:"Verify that Diun is running."`
}
)

Expand Down
2 changes: 2 additions & 0 deletions internal/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Client struct {
notif *notif.Client
pb.UnimplementedImageServiceServer
pb.UnimplementedNotifServiceServer
pb.UnimplementedHealthcheckServiceServer
}

// New creates a new grpc instance
Expand All @@ -36,6 +37,7 @@ func New(authority string, db *db.Client, notif *notif.Client) (*Client, error)
c.server = grpc.NewServer()
pb.RegisterImageServiceServer(c.server, c)
pb.RegisterNotifServiceServer(c.server, c)
pb.RegisterHealthcheckServiceServer(c.server, c)

return c, nil
}
Expand Down
13 changes: 13 additions & 0 deletions internal/grpc/healthcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package grpc

import (
"context"

"github.com/crazy-max/diun/v4/pb"
)

func (c *Client) Healthcheck(_ context.Context, _ *pb.HealthcheckRequest) (*pb.HealthcheckResponse, error) {
return &pb.HealthcheckResponse{
Message: "Diun is running",
}, nil
}
2 changes: 1 addition & 1 deletion pb/gen.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package pb

//go:generate protoc --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. image.proto notif.proto
//go:generate protoc --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. image.proto notif.proto healthcheck.proto
164 changes: 164 additions & 0 deletions pb/healthcheck.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions pb/healthcheck.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
option go_package = "github.com/crazy-max/diun/pb";

package pb;

message HealthcheckRequest {}

message HealthcheckResponse {
string message = 1;
}

service HealthcheckService {
rpc Healthcheck(HealthcheckRequest) returns (HealthcheckResponse) {}
}
121 changes: 121 additions & 0 deletions pb/healthcheck_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.