Documentation ¶
Index ¶
- func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) error
- func NewRouter(routers ...Router) *mux.Router
- func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error)
- type Address
- type Cart
- type CartsAPI
- func (c *CartsAPI) DeleteCart(w http.ResponseWriter, r *http.Request)
- func (c *CartsAPI) GetAllCarts(w http.ResponseWriter, r *http.Request)
- func (c *CartsAPI) GetCart(w http.ResponseWriter, r *http.Request)
- func (c *CartsAPI) Routes() Routes
- func (c *CartsAPI) StoreCart(w http.ResponseWriter, r *http.Request)
- type CartsAPIRouter
- type Coupon
- type LoginForm
- type MalformedInputError
- type Order
- type OrdersAPI
- type OrdersAPIRouter
- type Position
- type Product
- type ProductsAPI
- type ProductsAPIRouter
- type Route
- type Router
- type Routes
- type User
- type UsersAPI
- type UsersAPIRouter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeJSONResponse ¶
func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) error
EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code
Types ¶
type Address ¶
type Address struct { // The name of the person, company or similar. Name string `json:"name"` // The ISO 3166-1 alpha-2 country code. Country string `json:"country"` // The postal code code. PostalCode string `json:"postalCode"` // The city. City string `json:"city"` // The street name, number and any suffixes. Street string `json:"street"` }
Address - An address of a person, company or similar.
type Cart ¶
type Cart struct { // The UUID of the cart. ID string `json:"id"` Positions []Position `json:"positions"` // Whether the cart is locked. Locked bool `json:"locked,omitempty"` }
Cart - A cart containing products.
type CartsAPI ¶
type CartsAPI struct { Authenticator *authentication.Authenticator CartController *controller.Cart ProductController *controller.Product }
A CartsAPI binds http requests to an api service and writes the service results to the http response
func (*CartsAPI) DeleteCart ¶
func (c *CartsAPI) DeleteCart(w http.ResponseWriter, r *http.Request)
DeleteCart - Delete a cart
func (*CartsAPI) GetAllCarts ¶
func (c *CartsAPI) GetAllCarts(w http.ResponseWriter, r *http.Request)
GetAllCarts - Get all carts
func (*CartsAPI) GetCart ¶
func (c *CartsAPI) GetCart(w http.ResponseWriter, r *http.Request)
GetCart - Get a cart
type CartsAPIRouter ¶
type CartsAPIRouter interface { DeleteCart(http.ResponseWriter, *http.Request) GetAllCarts(http.ResponseWriter, *http.Request) GetCart(http.ResponseWriter, *http.Request) StoreCart(http.ResponseWriter, *http.Request) }
CartsAPIRouter defines the required methods for binding the api requests to a responses for the CartsApi The CartsAPIRouter implementation should parse necessary information from the http request, pass the data to a CartsApiServicer to perform the required actions, then write the service results to the http response.
type Coupon ¶
type Coupon struct { // The coupon display text. Name string `json:"name"` // The case-insensitive coupon code. Code string `json:"code"` // The discount in percent on the product price. Discount int32 `json:"discount"` Product Product `json:"product"` // The time when this coupon exires. If omitted the server chooses a time in the future. ExpiresAt time.Time `json:"expiresAt,omitempty"` }
Coupon - A coupon for a product that can be used during checkout.
type MalformedInputError ¶
type MalformedInputError struct { // A human-readable message about what went wrong. Message string `json:"message"` // A JSON Pointer to the incorrect input value. Pointer string `json:"pointer"` }
MalformedInputError - The input is invalid.
type Order ¶
type Order struct { // The UUID of the order. ID string `json:"id"` // The status of the order. Status string `json:"status"` // The total price of this order. Price float32 `json:"price"` Buyer Address `json:"buyer"` Recipient Address `json:"recipient"` Coupons []string `json:"coupons,omitempty"` Positions []Position `json:"positions"` }
Order - An order.
type OrdersAPI ¶
type OrdersAPI struct { Authenticator *authentication.Authenticator OrderController *controller.Order CartController *controller.Cart ProductController *controller.Product }
A OrdersAPI binds http requests to an api service and writes the service results to the http response
func (*OrdersAPI) CreateOrderFromCart ¶
func (c *OrdersAPI) CreateOrderFromCart(w http.ResponseWriter, r *http.Request)
CreateOrderFromCart - Create order from cart
func (*OrdersAPI) PlaceOrder ¶
func (c *OrdersAPI) PlaceOrder(w http.ResponseWriter, r *http.Request)
PlaceOrder - Place order
type OrdersAPIRouter ¶
type OrdersAPIRouter interface { CreateOrderFromCart(http.ResponseWriter, *http.Request) PlaceOrder(http.ResponseWriter, *http.Request) }
OrdersAPIRouter defines the required methods for binding the api requests to a responses for the OrdersApi The OrdersAPIRouter implementation should parse necessary information from the http request, pass the data to a OrdersApiServicer to perform the required actions, then write the service results to the http response.
type Position ¶
type Position struct { // The quantity of the position. Quantity int32 `json:"quantity"` Product Product `json:"product"` // The total price of this position. Price float32 `json:"price"` // The total savings of this position. SavedPrice float32 `json:"savedPrice,omitempty"` }
Position - A position in a cart.
type Product ¶
type Product struct { // The UUID of the product. If a product has no id it is a virtual product, like a discount, and only for displaying purposes. ID string `json:"id,omitempty"` // The display name of the product. Name string `json:"name"` // The price of a single item of the product. Price float32 `json:"price,omitempty"` }
Product - A product of the shop.
type ProductsAPI ¶
type ProductsAPI struct { Authenticator *authentication.Authenticator ProductController *controller.Product }
A ProductsAPI binds http requests to an api service and writes the service results to the http response
func (*ProductsAPI) GetAllProducts ¶
func (c *ProductsAPI) GetAllProducts(w http.ResponseWriter, r *http.Request)
GetAllProducts - Get all products
func (*ProductsAPI) Routes ¶
func (c *ProductsAPI) Routes() Routes
Routes returns all of the api route for the ProductsApiController
func (*ProductsAPI) StoreCouponForProduct ¶
func (c *ProductsAPI) StoreCouponForProduct(w http.ResponseWriter, r *http.Request)
StoreCouponForProduct - Create product coupon
type ProductsAPIRouter ¶
type ProductsAPIRouter interface { GetAllProducts(http.ResponseWriter, *http.Request) StoreCouponForProduct(http.ResponseWriter, *http.Request) }
ProductsAPIRouter defines the required methods for binding the api requests to a responses for the ProductsApi The ProductsAPIRouter implementation should parse necessary information from the http request, pass the data to a ProductsApiServicer to perform the required actions, then write the service results to the http response.
type Route ¶
type Route struct { Name string Method string Path string HandlerFunc http.HandlerFunc }
A Route defines the parameters for an api endpoint
type Router ¶
type Router interface {
Routes() Routes
}
Router defines the required methods for retrieving api routes
type User ¶
type User struct { // The UUID of the user. ID string `json:"id"` // The unique name of the user. Name string `json:"name"` // The plain text password of the user. Password string `json:"password,omitempty"` }
User - A user of the shop.
type UsersAPI ¶
type UsersAPI struct {
UserController *controller.User
}
A UsersAPI binds http requests to an api service and writes the service results to the http response
func (*UsersAPI) Login ¶
func (c *UsersAPI) Login(w http.ResponseWriter, r *http.Request)
Login - Login a user
type UsersAPIRouter ¶
type UsersAPIRouter interface { Login(http.ResponseWriter, *http.Request) Register(http.ResponseWriter, *http.Request) }
UsersAPIRouter defines the required methods for binding the api requests to a responses for the UsersApi The UsersAPIRouter implementation should parse necessary information from the http request, pass the data to a UsersApiServicer to perform the required actions, then write the service results to the http response.