Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
feat: implement grpc health service checking database connection (#4499)
Amir Ehsandare75ef0964d86
diff --git a/server/router/api/v1/health_service.go b/server/router/api/v1/health_service.gonew file mode 100644index 000000000..47a00c86d--- /dev/null+++ b/server/router/api/v1/health_service.go@@ -0,0 +1,21 @@+package v1++import (+ "context"++ "google.golang.org/grpc/codes"+ "google.golang.org/grpc/health/grpc_health_v1"+ "google.golang.org/grpc/status"++ "github.com/usememos/memos/store"+)++func (s *APIV1Service) Check(ctx context.Context,+ _ *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error) {+ history, err := s.Store.GetDriver().FindMigrationHistoryList(ctx, &store.FindMigrationHistory{})+ if err != nil || len(history) == 0 {+ return nil, status.Errorf(codes.Unavailable, "not available")+ }++ return &grpc_health_v1.HealthCheckResponse{Status: grpc_health_v1.HealthCheckResponse_SERVING}, nil+}diff --git a/server/router/api/v1/v1.go b/server/router/api/v1/v1.goindex a8ba11fd0..901d141ec 100644--- a/server/router/api/v1/v1.go+++ b/server/router/api/v1/v1.go@@ -11,6 +11,7 @@ import ("github.com/labstack/echo/v4/middleware""google.golang.org/grpc""google.golang.org/grpc/credentials/insecure"+ "google.golang.org/grpc/health/grpc_health_v1""google.golang.org/grpc/reflection"v1pb "github.com/usememos/memos/proto/gen/api/v1"@@ -19,6 +20,8 @@ import ()type APIV1Service struct {+ grpc_health_v1.UnimplementedHealthServer+v1pb.UnimplementedWorkspaceServiceServerv1pb.UnimplementedWorkspaceSettingServiceServerv1pb.UnimplementedAuthServiceServer@@ -46,6 +49,7 @@ func NewAPIV1Service(secret string, profile *profile.Profile, store *store.StoreStore: store,grpcServer: grpcServer,}+ grpc_health_v1.RegisterHealthServer(grpcServer, apiv1Service)v1pb.RegisterWorkspaceServiceServer(grpcServer, apiv1Service)v1pb.RegisterWorkspaceSettingServiceServer(grpcServer, apiv1Service)v1pb.RegisterAuthServiceServer(grpcServer, apiv1Service)