Skip to content

Commit

Permalink
feat: Remove default log library and use zerolog in grpc/server.go an…
Browse files Browse the repository at this point in the history
…d add logs to indicate health checks and stopping server in grpc_service.go and http_service.go respectively.
  • Loading branch information
shumkovdenis committed May 18, 2023
1 parent bcc505b commit aa309fc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"log"
"net"
"sync/atomic"

Expand All @@ -13,11 +12,10 @@ import (

pb "github.com/dapr/go-sdk/dapr/proto/runtime/v1"
"github.com/dapr/go-sdk/service/common"
"github.com/rs/zerolog/log"
)

func defaultHealthCheckHandler(ctx context.Context) error {
log.Println("health check handler not implemented")

return nil
}

Expand Down Expand Up @@ -108,6 +106,8 @@ func (s *server) AddHealthCheckHandler(_ string, fn common.HealthCheckHandler) e

// HealthCheck check app health status.
func (s *server) HealthCheck(ctx context.Context, _ *emptypb.Empty) (*pb.HealthCheckResponse, error) {
log.Info().Msg("health check")

if s.healthCheckHandler != nil {
if err := s.healthCheckHandler(ctx); err != nil {
return &pb.HealthCheckResponse{}, err
Expand Down
1 change: 1 addition & 0 deletions grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewGRPCService(cfg Config, caller Callee) error {

// terminate your environment gracefully before leaving main function
defer func() {
log.Info().Msg("stopping server")
server.GracefulStop()
}()

Expand Down
1 change: 1 addition & 0 deletions http_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewHTTPService(cfg Config, caller Callee) error {

// terminate your environment gracefully before leaving main function
defer func() {
log.Info().Msg("stopping server")
server.Shutdown()
}()

Expand Down

0 comments on commit aa309fc

Please sign in to comment.