api

package
v0.0.0-...-495f6ca Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrInternalServerError

func ErrInternalServerError(err error) render.Renderer

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrRender

func ErrRender(err error) render.Renderer

func Handler

func Handler(service service.Service) http.Handler

func NewEntryListResponse

func NewEntryListResponse(entries []model.Entry) []render.Renderer

func NewShoppingListsResponse

func NewShoppingListsResponse(lists []model.ShoppingList) []render.Renderer

func NewUsersResponse

func NewUsersResponse(users []model.User) []render.Renderer

Types

type AuthenticateRequest

type AuthenticateRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

func (*AuthenticateRequest) Bind

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

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 ShoppingList

type ShoppingList struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type ShoppingListEntry

type ShoppingListEntry struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Amount string `json:"amount"`
	Buy    bool   `json:"buy"`
}

type ShoppingListEntryRequest

type ShoppingListEntryRequest struct {
	*ShoppingListEntry
}

func (*ShoppingListEntryRequest) Bind

type ShoppingListEntryResponse

type ShoppingListEntryResponse struct {
	*ShoppingListEntry
}

func NewEntryResponse

func NewEntryResponse(entry model.Entry) *ShoppingListEntryResponse

func (*ShoppingListEntryResponse) Render

type ShoppingListRequest

type ShoppingListRequest struct {
	*ShoppingList
}

func (*ShoppingListRequest) Bind

func (s *ShoppingListRequest) Bind(r *http.Request) error

type ShoppingListResponse

type ShoppingListResponse struct {
	*ShoppingList
}

func NewShoppingListResponse

func NewShoppingListResponse(list model.ShoppingList) *ShoppingListResponse

func (*ShoppingListResponse) Render

type User

type User struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Password string `json:"password,omitempty"`
}

type UserRequest

type UserRequest struct {
	*User
}

func (*UserRequest) Bind

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

type UserResponse

type UserResponse struct {
	*User
}

func NewUserResponse

func NewUserResponse(u model.User) *UserResponse

func (*UserResponse) Render

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

Jump to

Keyboard shortcuts

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