Files
podinfo/pkg/api/status.go
stefanprodan 2479134e78 Implement swagger support
- add swagger definitions for all API routes
- self-host the swagger UI on `/swagger/`
- serve swagger spec on `/swagger.json`
2019-08-07 14:17:35 +03:00

29 lines
599 B
Go

package api
import (
"net/http"
"github.com/gorilla/mux"
"strconv"
)
// Status godoc
// @Summary Status code
// @Description sets the response status code to the specified code
// @Tags HTTP API
// @Accept json
// @Produce json
// @Router /status/{code} [get]
// @Success 200 {object} api.MapResponse
func (s *Server) statusHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
code, err := strconv.Atoi(vars["code"])
if err != nil {
s.ErrorResponse(w, r, err.Error(), http.StatusBadRequest)
return
}
s.JSONResponseCode(w, r, map[string]int{"status": code}, code)
}