mirror of
https://github.com/stefanprodan/podinfo.git
synced 2026-03-30 23:57:01 +00:00
34 lines
735 B
Go
34 lines
735 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
// Status godoc
|
|
// @Summary Status code
|
|
// @Description sets the response status code to the specified code
|
|
// @Tags HTTP API
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param code path int true "status code to return"
|
|
// @Router /status/{code} [get]
|
|
// @Success 200 {object} api.MapResponse
|
|
func (s *Server) statusHandler(w http.ResponseWriter, r *http.Request) {
|
|
_, span := s.tracer.Start(r.Context(), "statusHandler")
|
|
defer span.End()
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
code, err := strconv.Atoi(vars["code"])
|
|
if err != nil {
|
|
s.ErrorResponse(w, r, span, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
s.JSONResponseCode(w, r, map[string]int{"status": code}, code)
|
|
}
|