-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathhandlers.go
More file actions
42 lines (34 loc) · 1.07 KB
/
handlers.go
File metadata and controls
42 lines (34 loc) · 1.07 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
package srv
import (
"net/http"
"github.com/julienschmidt/httprouter"
pb "github.com/runconduit/conduit/controller/gen/public"
log "github.com/sirupsen/logrus"
)
type (
renderTemplate func(http.ResponseWriter, string, string, interface{}) error
serveFile func(http.ResponseWriter, string, string, interface{}) error
handler struct {
render renderTemplate
serveFile serveFile
apiClient pb.ApiClient
uuid string
controllerNamespace string
}
)
func (h *handler) handleIndex(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
params := appParams{UUID: h.uuid, ControllerNamespace: h.controllerNamespace}
version, err := h.apiClient.Version(req.Context(), &pb.Empty{}) // TODO: remove and call /api/version from web app
if err != nil {
params.Error = true
params.ErrorMessage = err.Error()
log.Error(err.Error())
} else {
params.Data = version
}
err = h.render(w, "app.tmpl.html", "base", params)
if err != nil {
log.Error(err.Error())
w.WriteHeader(http.StatusInternalServerError)
}
}