Documentation ¶
Index ¶
- Constants
- func HandleErrorWithCode(logger logrus.FieldLogger, w http.ResponseWriter, code int, ...)
- func LogRequest(next http.Handler) http.Handler
- func MattermostAuthorizationRequired(next http.Handler) http.Handler
- func ReturnJSON(w http.ResponseWriter, pointerToObject interface{}, httpStatus int)
- type Context
- type ErrorHandler
- func (h *ErrorHandler) HandleError(w http.ResponseWriter, logger logrus.FieldLogger, internalErr error)
- func (h *ErrorHandler) HandleErrorWithCode(w http.ResponseWriter, logger logrus.FieldLogger, code int, ...)
- func (h *ErrorHandler) PermissionsCheck(w http.ResponseWriter, logger logrus.FieldLogger, checkOutput error) bool
- type Handler
- type TestHandler
- type TestResponse
Constants ¶
const MaxRequestSize = 5 * 1024 * 1024 // 5MB
MaxRequestSize is the size limit for any incoming request The default limit set by mattermost-server is the configured max file size, and it sometimes isn't small enough to prevent some scenarios.
This is important to prevent huge payloads from being sent that could end in a bigger problem.
If an endpoint needs a smaller limit than this one, it could be solved by adding their own limit BEFORE reading the request body `r.Body = http.MaxBytesReader(w, r.Body, MaxRequestSize)`
Variables ¶
This section is empty.
Functions ¶
func HandleErrorWithCode ¶
func HandleErrorWithCode(logger logrus.FieldLogger, w http.ResponseWriter, code int, publicErrorMsg string, internalErr error)
HandleErrorWithCode logs the internal error and sends the public facing error message as JSON in a response with the provided code.
func LogRequest ¶
LogRequest logs each request, attaching a unique request_id to the request context to trace logs throughout the request lifecycle.
func MattermostAuthorizationRequired ¶
MattermostAuthorizationRequired checks if request is authorized.
func ReturnJSON ¶
func ReturnJSON(w http.ResponseWriter, pointerToObject interface{}, httpStatus int)
ReturnJSON writes the given pointerToObject as json with the provided httpStatus
Types ¶
type ErrorHandler ¶
type ErrorHandler struct { }
func (*ErrorHandler) HandleError ¶
func (h *ErrorHandler) HandleError(w http.ResponseWriter, logger logrus.FieldLogger, internalErr error)
HandleError logs the internal error and sends a generic error as JSON in a 500 response.
func (*ErrorHandler) HandleErrorWithCode ¶
func (h *ErrorHandler) HandleErrorWithCode(w http.ResponseWriter, logger logrus.FieldLogger, code int, publicErrorMsg string, internalErr error)
HandleErrorWithCode logs the internal error and sends the public facing error message as JSON in a response with the provided code.
func (*ErrorHandler) PermissionsCheck ¶
func (h *ErrorHandler) PermissionsCheck(w http.ResponseWriter, logger logrus.FieldLogger, checkOutput error) bool
PermissionsCheck handles the output of a permission check Automatically does the proper error handling. Returns true if the check passed and false on failure. Correct use is: if !h.PermissionsCheck(w, check) { return }
type Handler ¶
type Handler struct { *ErrorHandler APIRouter *mux.Router // contains filtered or unexported fields }
Handler Root API handler.
func NewHandler ¶
NewHandler constructs a new handler.
type TestHandler ¶
type TestHandler struct { *ErrorHandler // contains filtered or unexported fields }
func NewTestHandler ¶
func NewTestHandler(router *mux.Router, api *pluginapi.Client) *TestHandler
type TestResponse ¶
type TestResponse struct {
UserID string
}