GetByID handles GET /hosts/:hostId.
(w http.ResponseWriter, r *http.Request)
| 117 | |
| 118 | // GetByID handles GET /hosts/:hostId. |
| 119 | func (h *HostsHandler) GetByID(w http.ResponseWriter, r *http.Request) { |
| 120 | hostID := chi.URLParam(r, "hostId") |
| 121 | host, err := h.hosts.GetByID(r.Context(), hostID) |
| 122 | if err != nil || host == nil { |
| 123 | Error(w, http.StatusNotFound, "Host not found") |
| 124 | return |
| 125 | } |
| 126 | groups, _ := h.hosts.GetHostGroups(r.Context(), host.ID) |
| 127 | JSON(w, http.StatusOK, hostToResponse(host, groups)) |
| 128 | } |
| 129 | |
| 130 | // Create handles POST /hosts/create. |
| 131 | func (h *HostsHandler) Create(w http.ResponseWriter, r *http.Request) { |
no test coverage detected