Documentation ¶
Index ¶
- Constants
- func AssertHTTPError(t *testing.T, err *HTTPError, expectedStatus int, expectedMessage string)
- func CommonSetup(body string) (*response.Writer, *http.Request, database.Connection)
- func DisplayHTTPError(w *response.Writer, httpError *HTTPError) bool
- func GetRequestBodyAndContext(r *http.Request, ptr any, paramKeys ...string) (*database.User, *RouteParams, *HTTPError)
- func GetRequestContext(r *http.Request, paramKeys ...string) (*database.User, *RouteParams, *HTTPError)
- func ProcessHTTPError(w *response.Writer, httpError *HTTPError) bool
- func SetContext(t *testing.T, req *http.Request, user *database.User, params map[string]string) *http.Request
- type HTTPError
- type RouteParams
Constants ¶
const ( USERNAME_KEY = "username" CHAT_ID_KEY = "chatID" CHAT_NAME_KEY = "chatName" ACTION_KEY = "action" )
Variables ¶
This section is empty.
Functions ¶
func AssertHTTPError ¶
func CommonSetup ¶
Creates mock resolver arguments
func DisplayHTTPError ¶
Provides an error div for HTMX
func GetRequestBodyAndContext ¶
func GetRequestBodyAndContext( r *http.Request, ptr any, paramKeys ...string, ) (*database.User, *RouteParams, *HTTPError)
Calls `resolverutils.GetRequestBody()` then, if successful, `resolverutils.GetRequestContext()`
func GetRequestContext ¶
func GetRequestContext(r *http.Request, paramKeys ...string) (*database.User, *RouteParams, *HTTPError)
Gets all requested context attached to a request. Writes an HTTP error response + logs on failure.
func ProcessHTTPError ¶
Writes message and status of HTTPError to the response Returns false if httpError is nil, true otherwise
Types ¶
type HTTPError ¶
func GetRequestBody ¶
Decodes JSON from HTTP request body and binds it to a struct pointer. Writes an HTTP error response on failure.
func GetRequestQueryParam ¶
Extracts query parameter from request errors if missing when isRequired is true errors if the parameter value is an empty string
func GetRequestQueryParamInt ¶
Calls GetRequestQueryParam, then casts the result to an integer
func HandleDatabaseError ¶
Handles an unexpected error from the database