http

package
v0.0.0-...-fd12d58 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadRequest returns status 400 Bad Request for malformed request body.
	ErrBadRequest = &ErrResponse{HTTPStatusCode: http.StatusBadRequest, StatusText: http.StatusText(http.StatusBadRequest)}

	// ErrUnauthorized returns 401 Unauthorized.
	ErrUnauthorized = &ErrResponse{HTTPStatusCode: http.StatusUnauthorized, StatusText: http.StatusText(http.StatusUnauthorized)}

	// ErrForbidden returns status 403 Forbidden for unauthorized request.
	ErrForbidden = &ErrResponse{HTTPStatusCode: http.StatusForbidden, StatusText: http.StatusText(http.StatusForbidden)}

	// ErrNotFound returns status 404 Not Found for invalid resource request.
	ErrNotFound = &ErrResponse{HTTPStatusCode: http.StatusNotFound, StatusText: http.StatusText(http.StatusNotFound)}

	// ErrInternalServerError returns status 500 Internal Server Error.
	ErrInternalServerError = &ErrResponse{HTTPStatusCode: http.StatusInternalServerError, StatusText: http.StatusText(http.StatusInternalServerError)}
)

Functions

func ErrRender

func ErrRender(err error) render.Renderer

ErrRender returns status 422 Unprocessable Entity rendering response error.

Types

type DefaultDriverPort

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

func NewDefaultDriverPort

func NewDefaultDriverPort(postgresDb *pg.DB) DefaultDriverPort

NewDefaultDriverPort returns the default implementation of the driver port.

func (*DefaultDriverPort) CreateDriver

func (p *DefaultDriverPort) CreateDriver(w http.ResponseWriter, r *http.Request)

func (*DefaultDriverPort) SearchDriver

func (p *DefaultDriverPort) SearchDriver(w http.ResponseWriter, r *http.Request)

type DriverRequest

type DriverRequest struct {
	*models.Driver
}

func (*DriverRequest) Bind

func (d *DriverRequest) Bind(r *http.Request) error

type DriverResponse

type DriverResponse struct {
	*models.Driver
}

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText       string            `json:"status"`           // user-level status message
	AppCode          int64             `json:"code,omitempty"`   // application-specific error code
	ErrorText        string            `json:"error,omitempty"`  // application-level error message, for debugging
	ValidationErrors validation.Errors `json:"errors,omitempty"` // user level model validation errors
}

ErrResponse renderer type for handling all sorts of errors.

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

Render sets the application-specific error code in AppCode.

Jump to

Keyboard shortcuts

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