mirror of
https://github.com/mpolden/echoip.git
synced 2024-11-10 15:37:24 +01:00
Merge pull request #59 from maximbaz/add-health-endpoint
Add /health endpoint
This commit is contained in:
commit
3497e6e28a
@ -159,6 +159,12 @@ func (s *Server) JSONHandler(w http.ResponseWriter, r *http.Request) *appError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) HealthHandler(w http.ResponseWriter, r *http.Request) *appError {
|
||||||
|
w.Header().Set("Content-Type", jsonMediaType)
|
||||||
|
w.Write([]byte(`{"status":"OK"}`))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) PortHandler(w http.ResponseWriter, r *http.Request) *appError {
|
func (s *Server) PortHandler(w http.ResponseWriter, r *http.Request) *appError {
|
||||||
response, err := s.newPortResponse(r)
|
response, err := s.newPortResponse(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -247,6 +253,9 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
func (s *Server) Handler() http.Handler {
|
func (s *Server) Handler() http.Handler {
|
||||||
r := NewRouter()
|
r := NewRouter()
|
||||||
|
|
||||||
|
// Health
|
||||||
|
r.Route("GET", "/health", s.HealthHandler)
|
||||||
|
|
||||||
// JSON
|
// JSON
|
||||||
r.Route("GET", "/", s.JSONHandler).Header("Accept", jsonMediaType)
|
r.Route("GET", "/", s.JSONHandler).Header("Accept", jsonMediaType)
|
||||||
r.Route("GET", "/json", s.JSONHandler)
|
r.Route("GET", "/json", s.JSONHandler)
|
||||||
|
@ -131,6 +131,7 @@ func TestJSONHandlers(t *testing.T) {
|
|||||||
{s.URL + "/port/65356", `{"error":"Invalid port: 65356"}`, 400},
|
{s.URL + "/port/65356", `{"error":"Invalid port: 65356"}`, 400},
|
||||||
{s.URL + "/port/31337", `{"ip":"127.0.0.1","port":31337,"reachable":true}`, 200},
|
{s.URL + "/port/31337", `{"ip":"127.0.0.1","port":31337,"reachable":true}`, 200},
|
||||||
{s.URL + "/foo", `{"error":"404 page not found"}`, 404},
|
{s.URL + "/foo", `{"error":"404 page not found"}`, 404},
|
||||||
|
{s.URL + "/health", `{"status":"OK"}`, 200},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user