package
0.0.0-20241219180511-27a867595d87
Repository: https://github.com/neilalexander/harmony.git
Documentation: pkg.go.dev
# Functions
ContextWithLogger creates a new context, which will use the given logger.
ErrorResponse returns an HTTP 500 JSONResponse with the stringified form of the given error.
GetLogger retrieves the logrus logger from the supplied context.
GetRequestID returns the request ID associated with this context, or the empty string if one is not associated with this context.
MakeJSONAPI creates an HTTP handler which always responds to incoming requests with JSON responses.
MatrixErrorResponse is a function that returns error responses in the standard Matrix Error format (errcode / error).
MessageResponse returns a JSONResponse with a 'message' key containing the given text.
NewJSONRequestHandler converts the given OnIncomingRequest function into a JSONRequestHandler.
Protect panicking HTTP requests from taking down the entire process, and log them using the correct logger, returning a 500 with a JSON response rather than abruptly closing the connection.
RandomString generates a pseudo-random string of length n.
RedirectResponse returns a JSONResponse which 302s the client to the given location.
RequestWithLogging sets up standard logging for http.Requests.
SetCORSHeaders sets unrestricted origin Access-Control headers on the response writer.
SortAndUnique sorts a list and removes duplicate entries in place.
Unique removes duplicate items from a sorted list in place.
UniqueStrings turns a list of strings into a sorted list of unique strings.
WithCORSOptions intercepts all OPTIONS requests and responds with CORS headers.
# Structs
JSONResponse represents an HTTP response which contains a JSON body.
# Interfaces
JSONRequestHandler represents an interface that must be satisfied in order to respond to incoming HTTP requests with JSON.