func createRouter() *echo.Echo { r := echo.New() r.SetHTTPErrorHandler(errorHandler) r.Use(mw.Logger()) r.Use(mw.Recover()) r.Use(cors()) r.Use(mw.StripTrailingSlash()) r.Use(auth()) account := r.Group("/account") account.Post("/login", login) account.Get("/ping", ping) account.Get("/settings", getSettings) account.Post("/settings", setSettings) account.Delete("/settings/:id", removeSetting) //account.Get("/takeout") casts := r.Group("/library/casts") casts.Get("", getCasts) casts.Post("", addCast) casts.Put("/:id", renameCast) casts.Delete("/:id", removeCast) episodes := r.Group("/library") episodes.Get("/newepisodes", getNewEpisodes) episodes.Get("/episodes/:castid", getEpisodes) episodes.Get("/episode/:id", getEpisode) episodes.Get("/episodes/label/:label", getEpisodesByLabel) events := r.Group("/library/events") events.Get("", getEvents) events.Post("", addEvents) labels := r.Group("/library/labels") labels.Get("", getLabels) labels.Post("", addLabel) labels.Put("/:id", updateLabel) labels.Delete("/:id", removeLabel) /*opml := r.Group("/library") opml.Get("/casts.opml") opml.Post("/casts.opml")*/ // Perhaps: // /newepisodes -> /episodes?since=0 // /episodes/label/:label -> /episodes?label=label return r }
func main() { // Echo instance e := echo.New() // Debug mode e.SetDebug(true) //------------ // Middleware //------------ // Logger e.Use(mw.Logger()) // Recover e.Use(mw.Recover()) // Basic auth e.Use(mw.BasicAuth(func(usr, pwd string) bool { if usr == "joe" && pwd == "secret" { return true } return false })) //------- // Slash //------- e.Use(mw.StripTrailingSlash()) // or // e.Use(mw.RedirectToSlash()) // Gzip e.Use(mw.Gzip()) // Routes e.Get("/", hello) // Start server e.Run(":1323") }