routes

package
v0.0.0-...-37af083 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Routes = []Route{
	{
		IsAPI:   true,
		Path:    "/cars",
		Methods: []string{"GET"},
		Handler: JSONHandler(Cars),
	},
	{
		IsAPI:   true,
		Path:    "/car/{rn}",
		Methods: []string{"GET"},
		Handler: JSONHandler(CarInfo),
	},
	{
		IsAPI:   true,
		Path:    "/departments",
		Methods: []string{"GET"},
		Handler: JSONHandler(Departments),
	},
	{
		IsAPI:   true,
		Path:    "/stats/deps/model",
		Methods: []string{"GET"},
		Handler: JSONHandler(StatsByModel),
	},
	{
		IsAPI:   true,
		Path:    "/stats/deps/type",
		Methods: []string{"GET"},
		Handler: JSONHandler(StatsByType),
	},
	{
		IsAPI:   true,
		Path:    "/rent",
		Methods: []string{"POST"},
		Handler: JSONHandler(Rent),
	},
	{
		IsAPI:   true,
		Path:    "/return",
		Methods: []string{"POST"},
		Handler: JSONHandler(Return),
	},
	{
		IsAPI:   true,
		Path:    "/rentjournal",
		Methods: []string{"GET"},
		Handler: JSONHandler(RentJournal),
	},
	{
		IsAPI:   true,
		Path:    "/rentjournal/{rn}",
		Methods: []string{"GET"},
		Handler: JSONHandler(RentJournal),
	},
	{
		IsAPI:   true,
		Path:    "/track/{car}/{x}/{y}",
		Methods: []string{"PUT"},
		Handler: JSONHandler(Tracking),
	},
	{
		IsAPI:   true,
		Path:    "/trackexp/{car}/{x}/{y}",
		Methods: []string{"PUT"},
		Handler: JSONHandler(TrackingExp),
	},

	{
		IsAPI:   false,
		Path:    "/",
		Methods: []string{"GET"},
		Handler: Index,
	},
	{
		IsAPI:   false,
		Path:    "/car",
		Methods: []string{"GET"},
		Handler: Car,
	},
	{
		IsAPI:   false,
		Path:    "/stats",
		Methods: []string{"GET"},
		Handler: Stats,
	},
	{
		IsAPI:   false,
		Path:    "/car/{rn}",
		Methods: []string{"GET"},
		Handler: Car,
	},
}

Routes - web appication routes

Functions

func Car

func Car(w http.ResponseWriter, r *http.Request)

Car - обработчик для страницы /car просмотр истории и действия с ТС

func CarInfo

func CarInfo(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

func Cars

func Cars(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

Cars - handler for api. Returns list of the cars

func Departments

func Departments(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

Departments - handler for api. Returns list of the departments

func ErrorHandler

func ErrorHandler(fn func(http.ResponseWriter, *http.Request) (int, error)) http.HandlerFunc

ErrorHandler - returns error in json

func GetHandler

func GetHandler(addon []Route, middlewares ...func(http.HandlerFunc) http.HandlerFunc) (*mux.Router, http.Handler)

func GetRoutes

func GetRoutes(db storage.Storage) *mux.Router

GetRoutes для тестирование встраивает в контекст storage

func Index

func Index(w http.ResponseWriter, r *http.Request)

Index - /index Стартовая страница просмотр истории проката автомобилей

func JSONHandler

func JSONHandler(next func(http.ResponseWriter, *http.Request) (interface{}, int, error)) http.HandlerFunc

JSONHandler - returns response in json or error

func Rent

func Rent(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

func RentJournal

func RentJournal(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

RentJournal - handler for api. Returns list of the rental cars

func Return

func Return(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

func Stats

func Stats(w http.ResponseWriter, r *http.Request)

Stats - обработчик для страницы просмотра статистики

func StatsByModel

func StatsByModel(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

TODO: test StatsByModel

func StatsByType

func StatsByType(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

TODO: test StatsByType

func Tracking

func Tracking(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

Tracking Handler для трекинга ТС

func TrackingExp

func TrackingExp(w http.ResponseWriter, r *http.Request) (interface{}, int, error)

Exp1: Tracking Handler для трекинга ТС

Types

type RentData

type RentData struct {
	RegNum   string `schema:"regnum"` // Номер ТС
	DeptCode string `schema:"dept"`   // Код подразделения
	Agent    string `schema:"agent"`  // Фио агента
}

func (RentData) Check

func (r RentData) Check() error

type Route

type Route struct {
	IsAPI   bool
	Path    string
	Methods []string
	Handler http.HandlerFunc
}

Route - using Routes for web application routes

Jump to

Keyboard shortcuts

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