// Copyright (C) 2017 Marius Schellenberger package main import ( "net/http" "github.com/gorilla/mux" ) type route struct { Path string Handler http.HandlerFunc Methods []string } func buildRoutes() http.Handler { m := mux.NewRouter() m.NotFoundHandler = notFoundHandler{} for _, v := range routes { m.HandleFunc(v.Path, v.Handler).Methods(v.Methods...) } return m } var routes = []route{ { "/", contextWrapper( indexHandler), []string{"GET"}, }, { "/bootstrap.css", contextWrapper( staticHandler), []string{"GET"}, }, { "/custom.css", contextWrapper( staticHandler), []string{"GET"}, }, { "/login", contextWrapper( loginHandler), []string{"GET", "POST"}, }, { "/search", contextWrapper( searchHandler), []string{"GET", "POST"}, }, { "/new", contextWrapper( wikiNewHandler), []string{"GET", "POST"}, }, { "/all", contextWrapper( allHandler), []string{"GET"}, }, { "/wiki/{title:[a-zA-Z0-9+]+$}", contextWrapper( wikiHandler), []string{"GET"}, }, { "/wiki/{title:[a-zA-Z0-9+]+}/md", contextWrapper( wikiMDHandler( wikiHandler)), []string{"GET"}, }, { "/wiki/{title:[a-zA-Z0-9+]+}/edit", contextWrapper( wikiEditHandler), []string{"GET", "POST"}, }, { "/wiki/{title:[a-zA-Z0-9+]+}/del", contextWrapper( wikiDelHandler), []string{"POST"}, }, { "/users", contextWrapper( adminAuthHandler( usersHandler)), []string{"GET"}, }, { "/user/new", contextWrapper( adminAuthHandler( userNewHandler)), []string{"GET", "POST"}, }, { "/user/del/{user:[a-z]+$}", contextWrapper( adminAuthHandler( userDelHandler)), []string{"GET", "POST"}, }, { "/user/unlock/{user:[a-z]+$}", contextWrapper( adminAuthHandler( userUnlockHandler)), []string{"POST"}, }, { "/user/edit/{user:[a-z]+$}", contextWrapper( userAuthHandler( userEditHandler)), []string{"GET", "POST"}, }, { "/logout", contextWrapper( logoutHandler), []string{"GET", "POST"}, }, }