rest

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxMemory = 32 << 20 // 32mb

DefaultMaxMemory defines the default max memory bytes that will be used when parsing a form request body.

Variables

This section is empty.

Functions

func BindBody

func BindBody(c echo.Context, i interface{}) error

BindBody binds request body content to i.

This is similar to `echo.BindBody()`, but for JSON requests uses custom json reader that **copies** the request body, allowing multiple reads.

func NormalizeUrl

func NormalizeUrl(originalUrl string) (string, error)

NormalizeUrl removes duplicated slashes from a url path.

func ReadJsonBodyCopy

func ReadJsonBodyCopy(r *http.Request, i interface{}) error

ReadJsonBodyCopy reads the request body into i by creating a copy of `r.Body` to allow multiple reads.

Types

type ApiError

type ApiError struct {
	Code    int            `json:"code"`
	Message string         `json:"message"`
	Data    map[string]any `json:"data"`
	// contains filtered or unexported fields
}

ApiError defines the properties for a basic api error response.

func NewApiError

func NewApiError(status int, message string, data any) *ApiError

NewApiError creates and returns new normalized `ApiError` instance.

func NewBadRequestError

func NewBadRequestError(message string, data any) *ApiError

NewBadRequestError creates and returns 400 `ApiError`.

func NewForbiddenError

func NewForbiddenError(message string, data any) *ApiError

NewForbiddenError creates and returns 403 `ApiError`.

func NewNotFoundError

func NewNotFoundError(message string, data any) *ApiError

NewNotFoundError creates and returns 404 `ApiError`.

func NewUnauthorizedError

func NewUnauthorizedError(message string, data any) *ApiError

NewUnauthorizedError creates and returns 401 `ApiError`.

func (*ApiError) Error

func (e *ApiError) Error() string

Error makes it compatible with the `error` interface.

func (*ApiError) RawData

func (e *ApiError) RawData() any

type UploadedFile

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

UploadedFile defines a single multipart uploaded file instance.

func FindUploadedFiles

func FindUploadedFiles(r *http.Request, key string) ([]*UploadedFile, error)

FindUploadedFiles extracts all form files of `key` from a http request and returns a slice with `UploadedFile` instances (if any).

func (*UploadedFile) Bytes

func (f *UploadedFile) Bytes() []byte

Bytes returns a slice with the file content.

func (*UploadedFile) Header

func (f *UploadedFile) Header() *multipart.FileHeader

Header returns the file header that comes with the multipart request.

func (*UploadedFile) Name

func (f *UploadedFile) Name() string

Name returns an assigned unique name to the uploaded file.

Jump to

Keyboard shortcuts

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