common

package
v0.378.1-next.5 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// An unexpected internal error happened.
	ErrInternal = "ERR_INTERNAL"
	// The input arguments provided are not valid.
	ErrInvalidInput = "ERR_INVALID_INPUT"
	// The input provided is malformed and cannot be parsed.
	ErrInputMalformed = "ERR_INPUT_MALFORMED"
	// Authentication failed when trying to identify the identity.
	ErrAuthenticationFailed = "ERR_AUTHENTICATION_FAILED"
	// Permission denied when trying to access some resource.
	ErrPermissionDenied = "ERR_PERMISSION_DENIED"
	// Record cannot be found with the provided parameters.
	ErrRecordNotFound = "ERR_RECORD_NOT_FOUND"
	// The path or action does not exist.
	ErrMethodNotFound = "ERR_ACTION_NOT_FOUND"
	// The HTTP method is not allowed for this request.
	ErrHttpMethodNotAllowed = "ERR_HTTP_METHOD_NOT_ALLOWED"
)

Variables

This section is empty.

Functions

func HasContentType added in v0.378.0

func HasContentType(headers http.Header, mimetype string) bool

func ParseQueryParams added in v0.378.0

func ParseQueryParams(r *http.Request) map[string]any

ParseQueryParams will parse the parmeters in the request query string.

func ParseRequestData added in v0.378.0

func ParseRequestData(r *http.Request) (any, error)

ParseRequestData will parse the request based on the Content-Type header. Defaults to parsing as a JSON request body.

Types

type HandlerFunc added in v0.372.0

type HandlerFunc func(r *http.Request) Response

type PermissionState

type PermissionState struct {
	Status PermissionStatus `json:"status"`
}

func NewPermissionState

func NewPermissionState() *PermissionState

func (*PermissionState) Grant

func (ps *PermissionState) Grant()

type PermissionStatus

type PermissionStatus string
const (
	PermissionGranted PermissionStatus = "granted"
	PermissionUnknown PermissionStatus = "unknown"
)

type Response

type Response struct {
	Status  int
	Body    []byte
	Headers map[string][]string
}

func InternalServerErrorResponse added in v0.373.0

func InternalServerErrorResponse(ctx context.Context, err error) Response

func NewJsonResponse

func NewJsonResponse(status int, body any, meta *ResponseMetadata) Response

func NewRedirectResponse added in v0.373.0

func NewRedirectResponse(url *url.URL) Response

type ResponseMetadata added in v0.373.0

type ResponseMetadata struct {
	Headers http.Header
	Status  int
}

type RuntimeError

type RuntimeError struct {
	Code    string
	Message string
}

func NewAuthenticationFailedErr

func NewAuthenticationFailedErr() RuntimeError

func NewAuthenticationFailedMessageErr added in v0.368.0

func NewAuthenticationFailedMessageErr(message string) RuntimeError

func NewForeignKeyConstraintError

func NewForeignKeyConstraintError(column string) RuntimeError

func NewHttpMethodNotAllowedError added in v0.368.0

func NewHttpMethodNotAllowedError(message string) RuntimeError

func NewInputMalformedError added in v0.368.0

func NewInputMalformedError(message string) RuntimeError

func NewMethodNotFoundError added in v0.368.0

func NewMethodNotFoundError() RuntimeError

func NewNotFoundError

func NewNotFoundError() RuntimeError

func NewNotNullError

func NewNotNullError(column string) RuntimeError

func NewPermissionError

func NewPermissionError() RuntimeError

func NewUniquenessError

func NewUniquenessError(columns []string) RuntimeError

func NewValidationError added in v0.368.0

func NewValidationError(message string) RuntimeError

func (RuntimeError) Error

func (r RuntimeError) Error() string

func (RuntimeError) Extensions

func (r RuntimeError) Extensions() map[string]any

Jump to

Keyboard shortcuts

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