Documentation ¶
Index ¶
- func RespondWithMessage(w http.ResponseWriter, status int, message string)
- type Config
- type GetProductResponse
- type GetProductsResponse
- type GetShoppingCartHandler
- type Product
- type Server
- func (s *Server) AddProductHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) AddProductToShoppingCartHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) AuthGoogleLogin(w http.ResponseWriter, r *http.Request)
- func (s *Server) AuthGoogleRedirect(w http.ResponseWriter, r *http.Request)
- func (s *Server) DeleteProductFromShoppingCartHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) DeleteProductHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetProductHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetProductsHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetShoppingCartHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) HomeHandler(w http.ResponseWriter, r *http.Request) error
- func (s *Server) JWTAuthentication(next http.Handler) http.Handler
- func (s *Server) LoginHandler(w http.ResponseWriter, r *http.Request) error
- func (s *Server) SignUpHandler(w http.ResponseWriter, r *http.Request) error
- func (s *Server) Start()
- type ShoppingCart
- type TokenClaims
- type User
- type UserCredentials
- type UserError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RespondWithMessage ¶
func RespondWithMessage(w http.ResponseWriter, status int, message string)
RespondWithMessage sends message string to response writer
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config stores application configuration
type GetProductResponse ¶
type GetProductResponse struct {
Product Product `json:"product"`
}
GetProductResponse is a response for GetProductHandler
type GetProductsResponse ¶
type GetProductsResponse struct {
Products []Product `json:"products"`
}
GetProductsResponse is a response for GetProductsHandler
type GetShoppingCartHandler ¶
type GetShoppingCartHandler struct { Products []Product `json:"products"` Subtotal float64 `json:"price"` }
AddProductToShoppingCartResponse is a response for AddProductToShoppingCartHandler
type Product ¶
type Product struct { mgm.DefaultModel `bson:",inline"` Title string `json:"title"` Price float64 `json:"price"` }
Product is a sellable element
func NewProduct ¶
func ReturnProductSlice ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server keeps track of router, config and more
func (*Server) AddProductHandler ¶
func (s *Server) AddProductHandler(w http.ResponseWriter, r *http.Request)
AddProductHandler creates a new product
func (*Server) AddProductToShoppingCartHandler ¶
func (s *Server) AddProductToShoppingCartHandler(w http.ResponseWriter, r *http.Request)
func (*Server) AuthGoogleLogin ¶
func (s *Server) AuthGoogleLogin(w http.ResponseWriter, r *http.Request)
AuthGoogleLogin redirects user to Google login page
func (*Server) AuthGoogleRedirect ¶
func (s *Server) AuthGoogleRedirect(w http.ResponseWriter, r *http.Request)
AuthGoogleRedirect handles redirect from Google and signs in user
func (*Server) DeleteProductFromShoppingCartHandler ¶
func (s *Server) DeleteProductFromShoppingCartHandler(w http.ResponseWriter, r *http.Request)
func (*Server) DeleteProductHandler ¶
func (s *Server) DeleteProductHandler(w http.ResponseWriter, r *http.Request)
DeleteProductHandler deletes a product
func (*Server) GetProductHandler ¶
func (s *Server) GetProductHandler(w http.ResponseWriter, r *http.Request)
GetProductHandler returns product by id
func (*Server) GetProductsHandler ¶
func (s *Server) GetProductsHandler(w http.ResponseWriter, r *http.Request)
GetProductsHandler returns all products
func (*Server) GetShoppingCartHandler ¶
func (s *Server) GetShoppingCartHandler(w http.ResponseWriter, r *http.Request)
func (*Server) HomeHandler ¶
HomeHandler gives basic details about API
func (*Server) JWTAuthentication ¶
JWTAuthentication is a middleware that checks authentication
func (*Server) LoginHandler ¶
LoginHandler handles user login
func (*Server) SignUpHandler ¶
SignUpHandler handles user sign up
type ShoppingCart ¶
type ShoppingCart struct { mgm.DefaultModel `bson:",inline"` Products []Product `json:"products"` Subtotal float64 `json:"price"` }
func NewShoppingCart ¶
func NewShoppingCart(products []Product, subtotal float64) ShoppingCart
type TokenClaims ¶
type TokenClaims struct { UserID string jwt.StandardClaims }
TokenClaims is used to create JWT token
type User ¶
type User struct { mgm.DefaultModel `bson:",inline"` Email string `json:"email"` Password string `json:"-"` GoogleUserID string `json:"-" bson:"google_user_id"` }
User is used to store user information
type UserCredentials ¶
UserCredentials are used for signup and login