renderJSON renders the response data as "application/json" with the status code. It may report status 500 Internal Server Error if there is any failure in converting the response data to JSON document.
(w http.ResponseWriter, r *http.Request, statusCode int, data interface{})
| 236 | // It may report status 500 Internal Server Error if there is any failure in converting the |
| 237 | // response data to JSON document. |
| 238 | func renderJSON(w http.ResponseWriter, r *http.Request, statusCode int, data interface{}) { |
| 239 | w.Header().Set("Content-Type", "application/json") |
| 240 | w.WriteHeader(statusCode) |
| 241 | if err := json.NewEncoder(w).Encode(data); err != nil { |
| 242 | base.ErrorfCtx(r.Context(), "Error rendering JSON response: %s", err) |
| 243 | w.WriteHeader(http.StatusInternalServerError) |
| 244 | return |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // authHandler mocks the authentication process performed by the OAuth Authorization Server. |
| 249 | // The behavior of authHandler can be modified through the options map when needed. |