Skip to content

Commit

Permalink
service: Add health-check handler on /_health
Browse files Browse the repository at this point in the history
  • Loading branch information
deuill committed Oct 22, 2024
1 parent 0df6d2d commit eb21357
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generic junk files.
.DS_Store
.idea
*.log
tmp/

# Local configuration.
config.toml
12 changes: 12 additions & 0 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func (s *Service) Init(ctx context.Context) error {
return fmt.Errorf("no gateway configuration found")
}

// Set up request handlers.
if err := s.handler.Handle(s.handleHealth()); err != nil {
return fmt.Errorf("failed setting up request handler for health-checks: %w", err)
}

for _, g := range s.gateway {
if err := g.Init(ctx); err != nil {
return fmt.Errorf("failed initializing gateway: %w", err)
Expand Down Expand Up @@ -136,3 +141,10 @@ func (s *Service) UnmarshalTOML(data any) error {

return nil
}

// HandleHealth is an HTTP handler for health-checks.
func (s *Service) handleHealth() (string, http.HandlerFunc) {
return "/_health", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
}
}

0 comments on commit eb21357

Please sign in to comment.