Documentation
¶
Index ¶
- Variables
- func ErrInternalError(err error) render.Renderer
- func ErrInvalidRequest(err error) render.Renderer
- func ErrRender(err error) render.Renderer
- func ErrUnauthorized(err error) render.Renderer
- func NewItemListResponse(items []models.Item) []render.Renderer
- func NewItemPriceListResponse(itemPrices []models.ItemPrice) []render.Renderer
- func NewItemWithPriceListResponse(items []models.ItemWithPrice) []render.Renderer
- func NewUserItemListResponse(userItems []models.UserItem) []render.Renderer
- type ErrResponse
- type ItemPriceResponse
- type ItemRequest
- type ItemResponse
- type ItemWithPriceResponse
- type SessionResponse
- type SubscriptionRequest
- type UserItemResponse
- type UserRequest
- type UserResponse
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found."}
ErrNotFound is a standard response for a 404 code
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 ¶
ErrInternalError is a response payload with status code 500.
func ErrInvalidRequest ¶
ErrInvalidRequest is a response payload with status code 400.
func ErrUnauthorized ¶
ErrUnauthorized is a response payload with status code 401.
func NewItemListResponse ¶
NewItemListResponse generates a list of renders for Items
func NewItemPriceListResponse ¶
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
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 ¶
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 ¶
func (rd *ItemPriceResponse) Render(w http.ResponseWriter, r *http.Request) error
Render is preprocessing before the response is marshalled
type ItemRequest ¶
ItemRequest is the request payload for the Item data model
type ItemResponse ¶
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 ¶
func (rd *ItemWithPriceResponse) Render(w http.ResponseWriter, r *http.Request) error
Render is preprocessing before the response is marshalled
type SessionResponse ¶
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 ¶
func (rd *SessionResponse) Render(w http.ResponseWriter, r *http.Request) error
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
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 ¶
func (rd *UserItemResponse) Render(w http.ResponseWriter, r *http.Request) error
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
type UserResponse ¶
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