payloads

package
v0.0.0-...-da5f288 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found."}

ErrNotFound is a standard response for a 404 code

View Source
var ErrNotImplemented = &ErrResponse{HTTPStatusCode: 501, StatusText: "This website is not supported."}

ErrNotImplemented is a response payload with status code 501. This error is for creating items without the corresponding scraper

Functions

func ErrInternalError

func ErrInternalError(err error) render.Renderer

ErrInternalError is a response payload with status code 500.

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

ErrInvalidRequest is a response payload with status code 400.

func ErrRender

func ErrRender(err error) render.Renderer

ErrRender is a response payload with status code 422.

func ErrUnauthorized

func ErrUnauthorized(err error) render.Renderer

ErrUnauthorized is a response payload with status code 401.

func NewItemListResponse

func NewItemListResponse(items []models.Item) []render.Renderer

NewItemListResponse generates a list of renders for Items

func NewItemPriceListResponse

func NewItemPriceListResponse(itemPrices []models.ItemPrice) []render.Renderer

NewItemPriceListResponse generates a list of renders for Items

func NewItemWithPriceListResponse

func NewItemWithPriceListResponse(items []models.ItemWithPrice) []render.Renderer

NewItemWithPriceListResponse generates a list of renders for ItemWithPrices

func NewUserItemListResponse

func NewUserItemListResponse(userItems []models.UserItem) []render.Renderer

NewUserItemListResponse generates a list of renders for Items

Types

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

Render is required to implement the Renderer interface

type ItemPriceResponse

type ItemPriceResponse struct {
	ItemPrice *models.ItemPrice `json:"price"`
}

ItemPriceResponse is the response payload for the ItemPrice data model.

func NewItemPriceResponse

func NewItemPriceResponse(itemPrice *models.ItemPrice) *ItemPriceResponse

NewItemPriceResponse generate a Response for Item object

func (*ItemPriceResponse) Render

Render is preprocessing before the response is marshalled

type ItemRequest

type ItemRequest struct {
	Item *models.Item `json:"item"`
}

ItemRequest is the request payload for the Item data model

func (*ItemRequest) Bind

func (a *ItemRequest) Bind(r *http.Request) error

Bind is the postprocessing for the ItemRequest after the request is unmarshalled

type ItemResponse

type ItemResponse struct {
	Item *models.Item `json:"item"`
}

ItemResponse is the response payload for the Item data model.

func NewItemResponse

func NewItemResponse(item *models.Item) *ItemResponse

NewItemResponse generate a Response for Item object

func (*ItemResponse) Render

func (rd *ItemResponse) Render(w http.ResponseWriter, r *http.Request) error

Render is preprocessing before the response is marshalled

type ItemWithPriceResponse

type ItemWithPriceResponse struct {
	ItemWithPrice *models.ItemWithPrice `json:"item_with_price"`
}

ItemWithPriceResponse is the response payload for the ItemWithPrice data model.

func NewItemWithPriceResponse

func NewItemWithPriceResponse(item *models.ItemWithPrice) *ItemWithPriceResponse

NewItemWithPriceResponse generate a Response for ItemWithPrice object

func (*ItemWithPriceResponse) Render

Render is preprocessing before the response is marshalled

type SessionResponse

type SessionResponse struct {
	User *models.User `json:"user"`
	JWT  string       `json:"jwt"`
}

SessionResponse is the response payload for the Session data model.

func NewSessionResponse

func NewSessionResponse(jwt string, user *models.User) *SessionResponse

NewSessionResponse sends a user as well as the jwt token

func (*SessionResponse) Render

Render is preprocessing before the response is marshalled

type SubscriptionRequest

type SubscriptionRequest struct {
	Subscription *models.Subscription `json:"subscription"`
}

SubscriptionRequest is the request payload for the Subscription data model

func (*SubscriptionRequest) Bind

func (a *SubscriptionRequest) Bind(r *http.Request) error

Bind is the postprocessing for the ItemRequest after the request is unmarshalled

type UserItemResponse

type UserItemResponse struct {
	UserItem *models.UserItem `json:"user_item"`
	Valid    bool             `json:"valid"`
}

UserItemResponse is the response payload for the ItemPrice data model.

func NewUserItemResponse

func NewUserItemResponse(userItem *models.UserItem) *UserItemResponse

NewUserItemResponse generate a Response for Item object

func (*UserItemResponse) Render

Render is preprocessing before the response is marshalled

type UserRequest

type UserRequest struct {
	User *models.User `json:"user"`

	ProtectedID string `json:"id"` // override 'id' json to have more control
}

UserRequest is the request payload for the User data model

func (*UserRequest) Bind

func (a *UserRequest) Bind(r *http.Request) error

Bind is the postprocessing for the UserRequest after the request is unmarshalled

type UserResponse

type UserResponse struct {
	User    *models.User `json:"user"`
	Elapsed int64        `json:"elapsed"`
}

UserResponse is the response payload for the User data model.

func NewUserResponse

func NewUserResponse(user *models.User) *UserResponse

NewUserResponse generate a Response for User object

func (*UserResponse) Render

func (rd *UserResponse) Render(w http.ResponseWriter, r *http.Request) error

Render is preprocessing before the response is marshalled

Jump to

Keyboard shortcuts

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