-
Notifications
You must be signed in to change notification settings - Fork 6
/
list.go
48 lines (41 loc) · 970 Bytes
/
list.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
package controller
import (
"encoding/json"
"html/template"
"log"
"net/http"
"sync"
)
var listOnce sync.Once
var listT *template.Template
func (c *Controller) ListHandler(w http.ResponseWriter, r *http.Request) {
listOnce.Do(func() {
var err error
listT, err = template.ParseFiles(
c.root+"/templates/list/index.html",
c.root+"/templates/list/main.html",
)
if err != nil {
log.Printf("Failed to parse template: %v\n", err)
}
})
var data map[string]interface{}
err := listT.Execute(w, data)
if err != nil {
log.Printf("template execute error %s", err)
}
}
type TaskDelete struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
}
func (c *Controller) ListDeleteHandler(w http.ResponseWriter, req *http.Request) {
decoder := json.NewDecoder(req.Body)
var t TaskDelete
err := decoder.Decode(&t)
if err != nil {
panic(err)
}
log.Println(t.ID)
}