This repository has been archived by the owner on Aug 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
routes.go
43 lines (38 loc) · 2.06 KB
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package rebbleHandlers
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
// DummyHandler is useful for adding a route when the handler hasn't been
// completed/fleshed out yet.
func DummyHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(501)
w.Write([]byte("501 Not Implemented\n"))
fmt.Fprintf(w, "%s?%s\n%#v", r.URL.Path, r.URL.RawQuery, mux.Vars(r))
}
// Handlers returns a mux.Router with all possible routes already setup.
func Handlers(context *HandlerContext) *mux.Router {
r := mux.NewRouter()
r.Handle("/", routeHandler{context, HomeHandler}).Methods("GET")
r.Handle("/dev/apps/get_apps/page/{page:[0-9]+}", routeHandler{context, AppsHandler}).Methods("GET")
r.Handle("/dev/apps/get_app/id/{id}", routeHandler{context, AppHandler}).Methods("GET")
r.Handle("/dev/apps/get_tags/id/{id}", routeHandler{context, TagsHandler}).Methods("GET")
r.Handle("/dev/apps/get_versions/id/{id}", routeHandler{context, VersionsHandler}).Methods("GET")
r.Handle("/dev/apps/get_collection/id/{id}", routeHandler{context, CollectionHandler}).Methods("GET")
r.Handle("/dev/apps/search/{query}", routeHandler{context, SearchHandler}).Methods("GET")
r.Handle("/dev/author/id/{id}", routeHandler{context, AuthorHandler}).Methods("GET")
r.Handle("/admin/rebuild/db", routeHandler{context, AdminRebuildDBHandler}).Host("localhost")
r.Handle("/admin/rebuild/images", routeHandler{context, AdminRebuildImagesHandler}).Host("localhost")
r.Handle("/admin/version", routeHandler{context, AdminVersionHandler})
//r.HandleFunc("/boot/{path:.*}", BootHandler).Methods("GET")
// Added OS parameter
r.Handle("/boot/{os}/{path:.*}", routeHandler{context, BootHandler}).Methods("GET")
r.Handle("/images/{image}", routeHandler{context, ImagesHandler}).Methods("GET")
// The boot parameter wasn't working when set to /boot/ and this was used as
// an alternative. However, using the {path:.*} matching appears to have
// solved this issue. For future reference, the below snippet has been left,
// commented out.
//r.PathPrefix("/boot/").Methods("GET").HandlerFunc(BootHandler)
return r
}