2016-04-18 00:20:06 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Route struct {
|
|
|
|
Name string
|
|
|
|
Method string
|
|
|
|
Pattern string
|
|
|
|
HandlerFunc http.HandlerFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
type Routes []Route
|
|
|
|
|
|
|
|
func NewRouter() *mux.Router {
|
|
|
|
router := mux.NewRouter().StrictSlash(true)
|
|
|
|
|
|
|
|
for _, route := range routes {
|
|
|
|
router.
|
|
|
|
Methods(route.Method).
|
|
|
|
Path(route.Pattern).
|
|
|
|
Name(route.Name).
|
|
|
|
Handler(route.HandlerFunc)
|
|
|
|
}
|
|
|
|
|
|
|
|
return router
|
|
|
|
}
|
|
|
|
|
|
|
|
var routes = Routes{
|
|
|
|
Route{
|
|
|
|
"Index",
|
|
|
|
"GET",
|
|
|
|
"/",
|
|
|
|
Index,
|
2016-04-18 02:18:16 +02:00
|
|
|
}, {
|
|
|
|
"ListInstalledMods",
|
|
|
|
"GET",
|
|
|
|
"/mods/list/installed",
|
|
|
|
ListInstalledMods,
|
2016-04-18 00:20:06 +02:00
|
|
|
}, {
|
|
|
|
"ListMods",
|
|
|
|
"GET",
|
|
|
|
"/mods/list",
|
|
|
|
ListMods,
|
|
|
|
}, {
|
|
|
|
"ToggleMod",
|
|
|
|
"GET",
|
|
|
|
"/mods/toggle/{mod}",
|
|
|
|
ToggleMod,
|
2016-04-18 02:18:16 +02:00
|
|
|
}, {
|
|
|
|
"ListSaves",
|
|
|
|
"GET",
|
|
|
|
"/saves/list",
|
|
|
|
ListSaves,
|
2016-04-18 00:20:06 +02:00
|
|
|
},
|
|
|
|
}
|