common

package
v0.38.0-preview.0.0.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultMaxRequestSize = 2 << 20 // 2MB

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

Error is implementation of status error.

func NewBadRequestError

func NewBadRequestError(err error) *Error

NewBadRequestError creates a new bad request rest error.

func NewNotFoundError

func NewNotFoundError(msg string, err error) *Error

NewNotFoundError creates a new not found rest error.

func NewRestError

func NewRestError(status int, msg string, err error) *Error

NewRestError creates an error returned to user with provided status user displayed message and internal error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Status

func (e *Error) Status() int

Status returns error http status code.

func (*Error) UserMessage

func (e *Error) UserMessage() string

type HttpHandler

type HttpHandler struct {
	Logger zerolog.Logger
	Chain  flow.Chain

	MaxRequestSize int64
}

HttpHandler is custom http handler implementing custom handler function. HttpHandler function allows easier handling of errors and responses as it wraps functionality for handling error and responses outside of endpoint handling.

func NewHttpHandler

func NewHttpHandler(
	logger zerolog.Logger,
	chain flow.Chain,
	maxRequestSize int64,
) *HttpHandler

func (*HttpHandler) ErrorHandler

func (h *HttpHandler) ErrorHandler(w http.ResponseWriter, err error, errorLogger zerolog.Logger)

func (*HttpHandler) JsonResponse

func (h *HttpHandler) JsonResponse(w http.ResponseWriter, code int, response interface{}, errLogger zerolog.Logger)

JsonResponse builds a JSON response and send it to the client

func (*HttpHandler) VerifyRequest

func (h *HttpHandler) VerifyRequest(w http.ResponseWriter, r *http.Request) error

VerifyRequest function acts as a wrapper to each request providing common handling functionality such as logging, error handling

type Request

type Request struct {
	*http.Request
	ExpandFields map[string]bool

	Chain flow.Chain
	// contains filtered or unexported fields
}

Request a convenience wrapper around the http request to make it easy to read request query params

func Decorate

func Decorate(r *http.Request, chain flow.Chain) *Request

Decorate takes http request and applies functions to produce our custom request object decorated with values we need

func (*Request) Expands

func (rd *Request) Expands(field string) bool

func (*Request) GetQueryParam

func (rd *Request) GetQueryParam(name string) string

func (*Request) GetQueryParams

func (rd *Request) GetQueryParams(name string) []string

func (*Request) GetVar

func (rd *Request) GetVar(name string) string

func (*Request) GetVars

func (rd *Request) GetVars(name string) []string

func (*Request) Selects

func (rd *Request) Selects() []string

type StatusError

type StatusError interface {
	error                // this is the actual error that occured
	Status() int         // the HTTP status code to return
	UserMessage() string // the error message to return to the client
}

StatusError provides custom error with http status.

Directories

Path Synopsis
* Access API * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * * API version: 1.0.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
* Access API * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * * API version: 1.0.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

Jump to

Keyboard shortcuts

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