api

package
v0.0.2-alpha4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = ErrNotFound

Servers may also send 404 Not found instead of 403 Forbidden to hide the existence of a resource from an unauthorized client.

View Source
var ErrInvalidID error = errors.New("Invalid Item ID")
View Source
var ErrItemNotFount error = errors.New("Item not found")
View Source
var ErrNotFound = &ErrResponse{
	HTTPStatusCode: http.StatusNotFound,
	StatusText:     "Resource not found.",
}

Functions

func AuthenticatorSimpleSingleKey

func AuthenticatorSimpleSingleKey(key string) func(next http.Handler) http.Handler

func ErrInternal

func ErrInternal(err error) render.Renderer

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrRender

func ErrRender(err error) render.Renderer

func NewListResponse

func NewListResponse[T render.Renderer](items []T) []render.Renderer

Types

type CategoryRequest

type CategoryRequest struct{ models.Category }

func (*CategoryRequest) Bind

func (c *CategoryRequest) Bind(r *http.Request) error

type CategoryResponse

type CategoryResponse struct{ models.Category }

func (CategoryResponse) Render

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
}

ErrResponse renderer type for handling all sorts of errors.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

func (*ErrResponse) Render

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

type FreezerItemRequest

type FreezerItemRequest struct{ models.FreezerItem }

func (*FreezerItemRequest) Bind

func (c *FreezerItemRequest) Bind(r *http.Request) error

type FreezerItemResponse

type FreezerItemResponse struct{ models.FreezerItem }

func (FreezerItemResponse) Render

type ItemTypeRequest

type ItemTypeRequest struct{ models.ItemType }

func (*ItemTypeRequest) Bind

func (c *ItemTypeRequest) Bind(r *http.Request) error

type ItemTypeResponse

type ItemTypeResponse struct{ models.ItemType }

func (ItemTypeResponse) Render

type Server

type Server struct {
	Router *chi.Mux
	DB     *sqlx.DB
}

func CreateNewServer

func CreateNewServer(db *sqlx.DB) *Server

func (*Server) Doc

func (s *Server) Doc()

func (*Server) MountHandlers

func (s *Server) MountHandlers(key string)

Jump to

Keyboard shortcuts

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