sourcegraph/internal/httpserver/handler.go

24 lines
532 B
Go
Raw Permalink Normal View History

2020-11-02 16:31:41 +00:00
package httpserver
import (
"net/http"
"github.com/gorilla/mux"
)
// NewHandler creates an HTTP handler with a default /healthz endpoint.
// If a function is provided, it will be invoked with a router on which
// additional routes can be installed.
func NewHandler(setupRoutes func(router *mux.Router)) http.Handler {
router := mux.NewRouter()
router.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
})
if setupRoutes != nil {
setupRoutes(router)
}
return router
}