api

package
v0.0.0-...-920598c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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

func LogRequest(next http.Handler) http.Handler

LogRequest logs each request, attaching a unique request_id to the request context to trace logs throughout the request lifecycle.

func MattermostAuthorizationRequired

func MattermostAuthorizationRequired(next http.Handler) http.Handler

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 Context

type Context struct {
	// contains filtered or unexported fields
}

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

func NewHandler(pluginAPI *pluginapi.Client) *Handler

NewHandler constructs a new handler.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL