forked from predbdotovh/pre-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.go
More file actions
41 lines (32 loc) · 829 Bytes
/
router.go
File metadata and controls
41 lines (32 loc) · 829 Bytes
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
package main
import (
"net/http"
_ "github.com/go-sql-driver/mysql"
"github.com/gorilla/mux"
)
const hostname = "predb.ovh"
func newRouter() *mux.Router {
backendUpdates = make(chan triggerAction)
go backendPump()
router := mux.NewRouter().
StrictSlash(true).
Host(hostname).
PathPrefix("/api").
Subrouter()
for ver, jRoutes := range jsonRoutes {
versionRouter := router.PathPrefix("/" + ver).Subrouter()
for _, r := range jRoutes {
versionRouter.
Methods(r.Method).
Path(r.Pattern).
Name(r.Name).
Handler(logger(r.Handler, r.Name))
}
}
router.NotFoundHandler = http.HandlerFunc(notFound)
return router
}
func notFound(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
apiErr(w, "404 Not Found")
}