router.go 735 B

12345678910111213141516171819202122232425
  1. package main
  2. import (
  3. "net/http"
  4. "github.com/julienschmidt/httprouter"
  5. )
  6. func initRouter() *httprouter.Router {
  7. router := httprouter.New()
  8. router.GET("/", showIndex)
  9. router.GET("/games", listGames)
  10. router.PUT("/games", createGame)
  11. router.PUT("/games/:rows/:cols", createGame)
  12. router.GET("/games/:gameid", showGame)
  13. router.GET("/games/:gameid/:boardid", proxyHandler)
  14. //router.GET("/games/:gameid/players", playerListHandler)
  15. // TODO: /games/{id}/players/{playerId}
  16. router.POST("/games/:gameid/move/:playerId/:direction", movePlayer)
  17. router.PanicHandler = func(w http.ResponseWriter, r *http.Request, something interface{}) {
  18. http.Error(w, "Internal server error", http.StatusInternalServerError)
  19. }
  20. return router
  21. }