-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnode.go
49 lines (44 loc) · 1011 Bytes
/
node.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
44
45
46
47
48
49
package main
import (
"net/http"
"github.com/WeTrustPlatform/blockform/model"
"goji.io/pat"
)
func handleNode(w http.ResponseWriter, r *http.Request) {
id := pat.Param(r, "id")
http.Redirect(w, r, "/node/"+id+"/general", http.StatusSeeOther)
}
func handleNodeTab(w http.ResponseWriter, r *http.Request) {
id := pat.Param(r, "id")
tab := pat.Param(r, "tab")
node := model.Node{}
db.Find(&node, id)
events := []model.Event{}
db.Model(&node).Order("created_at DESC").Related(&events)
tmpl.ExecuteTemplate(w, "node_"+tab+".html", struct {
Tab string
Node model.Node
Events []model.Event
}{
tab,
node,
events,
})
}
func handleNodeExplorer(w http.ResponseWriter, r *http.Request) {
nodeID := pat.Param(r, "nodeid")
tab := "explorer"
class := pat.Param(r, "class")
id := pat.Param(r, "id")
node := model.Node{}
db.Find(&node, nodeID)
tmpl.ExecuteTemplate(w, "node_"+tab+"_"+class+".html", struct {
Tab string
ID string
Node model.Node
}{
tab,
id,
node,
})
}