Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rf: more idiomatic health endpoint #34

Merged
merged 1 commit into from
Jun 10, 2024
Merged
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
14 changes: 0 additions & 14 deletions handlers/health-check.go

This file was deleted.

11 changes: 11 additions & 0 deletions server/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@
h.ServeHTTP(w, r)
})
}

// HealthCheck returns the status of the application
func HealthCheck() http.Handler {
type Response struct {
Status string `json:"status"`
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(Response{Status: "ok"})
})

Check warning on line 51 in server/middleware.go

View check run for this annotation

Codecov / codecov/patch

server/middleware.go#L44-L51

Added lines #L44 - L51 were not covered by tests
}
9 changes: 5 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
func (s *Server) routes() {
s.mux.Handle("/", NotFound(nil))

s.mux.Handle("GET /api/headers", handlers.HandleGetHeaders())
s.mux.Handle("GET /api/cookies", handlers.HandleCookies())
s.mux.Handle("GET /api/carbon", handlers.HandleCarbon())
s.mux.Handle("GET /health", HealthCheck())

Check warning on line 28 in server/server.go

View check run for this annotation

Codecov / codecov/patch

server/server.go#L27-L28

Added lines #L27 - L28 were not covered by tests
s.mux.Handle("GET /api/block-lists", handlers.HandleBlockLists())
s.mux.Handle("GET /api/carbon", handlers.HandleCarbon())
s.mux.Handle("GET /api/cookies", handlers.HandleCookies())

Check warning on line 31 in server/server.go

View check run for this annotation

Codecov / codecov/patch

server/server.go#L30-L31

Added lines #L30 - L31 were not covered by tests
s.mux.Handle("GET /api/dns-server", handlers.HandleDNSServer())
s.mux.Handle("GET /api/dns", handlers.HandleDNS())
s.mux.Handle("GET /api/dnssec", handlers.HandleDnsSec())
s.mux.Handle("GET /api/firewall", handlers.HandleFirewall())
s.mux.Handle("GET /api/get-ip", handlers.HandleGetIP())
s.mux.Handle("GET /api/headers", handlers.HandleGetHeaders())

Check warning on line 37 in server/server.go

View check run for this annotation

Codecov / codecov/patch

server/server.go#L37

Added line #L37 was not covered by tests
s.mux.Handle("GET /api/hsts", handlers.HandleHsts())
s.mux.Handle("GET /api/http-security", handlers.HandleHttpSecurity())
s.mux.Handle("GET /api/legacy-rank", handlers.HandleLegacyRank())
Expand All @@ -44,7 +46,6 @@
s.mux.Handle("GET /api/social-tags", handlers.HandleGetSocialTags())
s.mux.Handle("GET /api/tls", handlers.HandleTLS())
s.mux.Handle("GET /api/trace-route", handlers.HandleTraceRoute())
s.mux.Handle("GET /health", handlers.HandleHealthCheck())
}

func (s *Server) Run() error {
Expand Down
Loading