Example #1
0
func init() {
	router := mux.NewRouter()
	router.Path("/js/{ver}/all.js").HandlerFunc(handler(allJS))
	router.Path("/css/{ver}/all.css").HandlerFunc(handler(allCSS))

	router.Path("/user").MatcherFunc(wantsJSON).HandlerFunc(handler(getUser))
	router.Path("/login").MatcherFunc(wantsHTML).HandlerFunc(handler(login))
	router.Path("/logout").MatcherFunc(wantsHTML).HandlerFunc(handler(logout))

	gamesRouter := router.PathPrefix("/games").MatcherFunc(wantsJSON).Subrouter()

	gameRouter := gamesRouter.PathPrefix("/{game_id}").Subrouter()
	gameRouter.Methods("GET").HandlerFunc(handler(getGame))

	gamesRouter.Methods("GET").HandlerFunc(handler(getGames))
	gamesRouter.Methods("POST").HandlerFunc(handler(createGame))

	aisRouter := router.PathPrefix("/ais").MatcherFunc(wantsJSON).Subrouter()

	aiRouter := aisRouter.PathPrefix("/{ai_id}").Subrouter()

	aiErrorsRouter := aiRouter.Path("/errors").Subrouter()
	aiErrorsRouter.Methods("GET").HandlerFunc(handler(getAIErrors))

	aiRouter.Methods("DELETE").HandlerFunc(handler(deleteAI))

	aisRouter.Methods("GET").HandlerFunc(handler(getAIs))
	aisRouter.Methods("POST").HandlerFunc(handler(createAI))

	router.Path("/examples/randomizer").Methods("POST").Handler(ai.HTTPHandlerFunc(common.GAELoggerFactory, randomizerAi.Randomizer{}))
	router.Path("/examples/simpleton").Methods("POST").Handler(ai.HTTPHandlerFunc(common.GAELoggerFactory, simpletonAi.Simpleton{}))
	router.Path("/examples/broken").Methods("POST").Handler(ai.HTTPHandlerFunc(common.GAELoggerFactory, brokenAi.Broken{}))

	handleStatic(router, "static")

	router.PathPrefix("/").MatcherFunc(wantsHTML).HandlerFunc(handler(index))
	http.Handle("/", router)
}
Example #2
0
func init() {
	http.Handle("/", ai.HTTPHandlerFunc(common.GAELoggerFactory, randomizerAi.Randomizer{}))
}