Repository navigation
Expand file tree
/
Copy pathrouters.go
More file actions
68 lines (53 loc) · 1.53 KB
/
Copy pathrouters.go
File metadata and controls
68 lines (53 loc) · 1.53 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package apiserver
import (
"net/http"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
// Route defines the route specifics.
type Route struct {
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
}
// Routes list of routes to be added to the server.
type Routes []Route
// NewRouter returns a new router with defaults.
func (api *APIServer) NewRouter() *mux.Router {
router := mux.NewRouter().StrictSlash(true)
router.
Methods("POST").
Path(RoutePathNodeBootstrapData).
Name("GetNodeBootstrapData").
HandlerFunc(api.GetNodeBootstrapData)
router.
Methods("POST").
Path(RoutePathLatestSIGImageConfig).
Name("GetLatestSigImageConfig").
HandlerFunc(api.GetLatestSigImageConfig)
router.
Methods("POST").
Path(RoutePathDistroSIGImageConfig).
Name("GetDistroSigImageConfig").
HandlerFunc(api.GetDistroSigImageConfig)
router.Methods("GET").Path("/healthz").Name("healthz").HandlerFunc(healthz)
// global timeout and panic handlers.
router.Use(timeoutHandler(), recoveryHandler())
return router
}
func healthz(w http.ResponseWriter, r *http.Request) {
handleOK(w, r)
}
func handleOK(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusOK)
}
func recoveryHandler() mux.MiddlewareFunc {
return handlers.RecoveryHandler(handlers.PrintRecoveryStack(true))
}
func timeoutHandler() mux.MiddlewareFunc {
return func(h http.Handler) http.Handler {
return http.TimeoutHandler(h, defaultTimeout, "")
}
}