api

package
v0.0.0-...-9f73338 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

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 Product

type Product struct {
	mgm.DefaultModel `bson:",inline"`
	Title            string  `json:"title"`
	Price            float64 `json:"price"`
	CreatedBy        string  `json:"created_by"`
}

Product is a sellable element

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) 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) 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) HomeHandler

func (s *Server) HomeHandler(w http.ResponseWriter, r *http.Request) error

HomeHandler gives basic details about API

func (*Server) JWTAuthentication

func (s *Server) JWTAuthentication(next http.Handler) http.Handler

JWTAuthentication is a middleware that checks authentication

func (*Server) LoginHandler

func (s *Server) LoginHandler(w http.ResponseWriter, r *http.Request) error

LoginHandler handles user login

func (*Server) SignUpHandler

func (s *Server) SignUpHandler(w http.ResponseWriter, r *http.Request) error

SignUpHandler handles user sign up

func (*Server) Start

func (s *Server) Start()

Start the server on port 8080

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

type UserCredentials struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

UserCredentials are used for signup and login

type UserError

type UserError struct {
	StatusCode int    `json:"-"`
	Message    string `json:"message"`
	Cause      error  `json:"-"`
}

UserError is used to indicate user what went wrong

func (UserError) Error

func (e UserError) Error() string

Jump to

Keyboard shortcuts

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