Skip to content

Commit

Permalink
api: add context to ready func
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatczuk committed Jul 11, 2023
1 parent a906054 commit 1d4014c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package forwarder

import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/pprof"
Expand All @@ -24,14 +25,14 @@ import (
// It provides health and readiness endpoints prometheus metrics, and pprof debug endpoints.
type APIHandler struct {
mux *http.ServeMux
ready func() bool
ready func(ctx context.Context) bool
config string
script string

patterns []string
}

func NewAPIHandler(r prometheus.Gatherer, ready func() bool, config, pac string) *APIHandler {
func NewAPIHandler(r prometheus.Gatherer, ready func(ctx context.Context) bool, config, pac string) *APIHandler {
m := http.NewServeMux()
a := &APIHandler{
mux: m,
Expand Down Expand Up @@ -72,7 +73,7 @@ func (h *APIHandler) healthz(w http.ResponseWriter, r *http.Request) {
}

func (h *APIHandler) readyz(w http.ResponseWriter, r *http.Request) {
if h.ready() {
if h.ready(r.Context()) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("OK"))
Expand Down
2 changes: 1 addition & 1 deletion http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,6 @@ func (hp *HTTPProxy) Addr() string {
}

// Ready returns true if the server is running and ready to accept requests.
func (hp *HTTPProxy) Ready() bool {
func (hp *HTTPProxy) Ready(ctx context.Context) bool {
return hp.Addr() != ""
}
2 changes: 1 addition & 1 deletion http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,6 @@ func (hs *HTTPServer) Addr() string {
}

// Ready returns true if the server is running and ready to accept requests.
func (hs *HTTPServer) Ready() bool {
func (hs *HTTPServer) Ready(ctx context.Context) bool {
return hs.Addr() != ""
}

0 comments on commit 1d4014c

Please sign in to comment.