httputils

package
v0.0.0-...-6f9a9ad Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ForbiddenError = ErrorResponse{
	Code:    http.StatusForbidden,
	Message: "forbidden",
}

ForbiddenError represents a forbidden error response

View Source
var UnauthorizedError = ErrorResponse{
	Code:    http.StatusUnauthorized,
	Message: "unauthorized",
}

UnauthorizedError represents a unauthorized error response

Functions

func RespondInternalServerError

func RespondInternalServerError(w http.ResponseWriter)

RespondInternalServerError responds with an internal server error response

func RespondJSON

func RespondJSON(w http.ResponseWriter, statusCode int, data interface{})

RespondJSON responds with a json with the given status code and data

func RespondText

func RespondText(w http.ResponseWriter, statusCode int, text string)

func RespondWithError

func RespondWithError(w http.ResponseWriter, err error)

RespondWithError responds with a json with the given status code and message

Types

type ErrorResponse

type ErrorResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ErrorResponse error response

func NewBadRequestError

func NewBadRequestError(msg string) ErrorResponse

NewBadRequestError returns a bad request error response

func NewNotFoundError

func NewNotFoundError(resourceName string) ErrorResponse

NewNotFoundError returns an ErrorResponse with the not found values

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

type PatchOperation

type PatchOperation struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	Value interface{} `json:"value"`
}

PatchOperation represents the request body of a patch request

type PatchRequest

type PatchRequest []PatchOperation

PatchRequest defines a general patch request

Jump to

Keyboard shortcuts

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