sourcegraph/internal/httpserver/handler.go
2020-11-02 10:31:41 -06:00

24 lines
532 B
Go

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
}