Example #1
0
func main() {
	router := qv.NewRouter()
	router.Get("/players", http.HandlerFunc(getPlayers))
	router.Post("/players", http.HandlerFunc(createPlayer))
	router.Delete("/players/:id", http.HandlerFunc(deletePlayer))
	router.Get("/games", http.HandlerFunc(getGames))
	router.Post("/games", http.HandlerFunc(createGame))
	router.Delete("/games/:id", http.HandlerFunc(deleteGame))
	router.Get("/standings", http.HandlerFunc(getStandings))
	http.Handle("/api/v1/", http.StripPrefix("/api/v1", router))
	http.Handle("/", NoDirListing(http.FileServer(http.Dir(config.assetPath))))

	listenAt := fmt.Sprintf("%s:%s", config.listenAddress, config.listenPort)
	fmt.Printf("Starting to listen on: %s\n", listenAt)

	if err := http.ListenAndServe(listenAt, nil); err != nil {
		os.Stderr.WriteString("Could not start web server!\n")
		os.Exit(1)
	}
}
Example #2
0
File: http.go Project: jackc/tpr
func NewAPIHandler(pool *pgx.ConnPool, mailer Mailer, logger log.Logger) http.Handler {
	router := qv.NewRouter()

	router.Post("/register", EnvHandler(pool, mailer, logger, RegisterHandler))
	router.Post("/sessions", EnvHandler(pool, mailer, logger, CreateSessionHandler))
	router.Delete("/sessions/:id", EnvHandler(pool, mailer, logger, AuthenticatedHandler(DeleteSessionHandler)))
	router.Post("/subscriptions", EnvHandler(pool, mailer, logger, AuthenticatedHandler(CreateSubscriptionHandler)))
	router.Delete("/subscriptions/:id", EnvHandler(pool, mailer, logger, AuthenticatedHandler(DeleteSubscriptionHandler)))
	router.Post("/request_password_reset", EnvHandler(pool, mailer, logger, RequestPasswordResetHandler))
	router.Post("/reset_password", EnvHandler(pool, mailer, logger, ResetPasswordHandler))
	router.Get("/feeds", EnvHandler(pool, mailer, logger, AuthenticatedHandler(GetFeedsHandler)))
	router.Post("/feeds/import", EnvHandler(pool, mailer, logger, AuthenticatedHandler(ImportFeedsHandler)))
	router.Get("/feeds.xml", EnvHandler(pool, mailer, logger, AuthenticatedHandler(ExportFeedsHandler)))
	router.Get("/items/unread", EnvHandler(pool, mailer, logger, AuthenticatedHandler(GetUnreadItemsHandler)))
	router.Post("/items/unread/mark_multiple_read", EnvHandler(pool, mailer, logger, AuthenticatedHandler(MarkMultipleItemsReadHandler)))
	router.Delete("/items/unread/:id", EnvHandler(pool, mailer, logger, AuthenticatedHandler(MarkItemReadHandler)))
	router.Get("/items/archived", EnvHandler(pool, mailer, logger, AuthenticatedHandler(GetArchivedItemsHandler)))
	router.Get("/account", EnvHandler(pool, mailer, logger, AuthenticatedHandler(GetAccountHandler)))
	router.Patch("/account", EnvHandler(pool, mailer, logger, AuthenticatedHandler(UpdateAccountHandler)))

	return router
}