(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc healthsdk.HealthcheckReport, dismissed ...healthsdk.HealthSection)
| 122 | } |
| 123 | |
| 124 | func formatHealthcheck(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc healthsdk.HealthcheckReport, dismissed ...healthsdk.HealthSection) { |
| 125 | // Mark any sections previously marked as dismissed. |
| 126 | for _, d := range dismissed { |
| 127 | switch d { |
| 128 | case healthsdk.HealthSectionAccessURL: |
| 129 | hc.AccessURL.Dismissed = true |
| 130 | case healthsdk.HealthSectionDERP: |
| 131 | hc.DERP.Dismissed = true |
| 132 | case healthsdk.HealthSectionDatabase: |
| 133 | hc.Database.Dismissed = true |
| 134 | case healthsdk.HealthSectionWebsocket: |
| 135 | hc.Websocket.Dismissed = true |
| 136 | case healthsdk.HealthSectionWorkspaceProxy: |
| 137 | hc.WorkspaceProxy.Dismissed = true |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | format := r.URL.Query().Get("format") |
| 142 | switch format { |
| 143 | case "text": |
| 144 | rw.Header().Set("Content-Type", "text/plain; charset=utf-8") |
| 145 | rw.WriteHeader(http.StatusOK) |
| 146 | |
| 147 | _, _ = fmt.Fprintln(rw, "time:", hc.Time.Format(time.RFC3339)) |
| 148 | _, _ = fmt.Fprintln(rw, "healthy:", hc.Healthy) |
| 149 | _, _ = fmt.Fprintln(rw, "derp:", hc.DERP.Healthy) |
| 150 | _, _ = fmt.Fprintln(rw, "access_url:", hc.AccessURL.Healthy) |
| 151 | _, _ = fmt.Fprintln(rw, "websocket:", hc.Websocket.Healthy) |
| 152 | _, _ = fmt.Fprintln(rw, "database:", hc.Database.Healthy) |
| 153 | |
| 154 | case "", "json": |
| 155 | httpapi.WriteIndent(ctx, rw, http.StatusOK, hc) |
| 156 | |
| 157 | default: |
| 158 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 159 | Message: fmt.Sprintf("Invalid format option %q.", format), |
| 160 | Detail: "Allowed values are: \"json\", \"simple\".", |
| 161 | }) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // @Summary Get health settings |
| 166 | // @ID get-health-settings |
no test coverage detected