-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_logs.go
More file actions
109 lines (92 loc) · 2.08 KB
/
handler_logs.go
File metadata and controls
109 lines (92 loc) · 2.08 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"fmt"
"log"
"net/http"
"text/template"
"wen/self-release/pkg/sse"
"github.com/labstack/echo"
)
func logsHandler(c echo.Context) (err error) {
project := c.FormValue("project")
branch := c.FormValue("branch") // branch includes tag
key := c.FormValue("key")
var note string
if project != "" && branch == "" {
branch = defaultDevBranch
note = "default"
}
var list bool
var stored bool
var existmsg string
type Item struct {
Key string
Project string
Branch string
}
items := []Item{}
// if project and key both not specified, list all keys
if project == "" && key == "" {
log.Println("getting logs list")
brokers, e := sse.GetBrokers()
if err != nil {
err = fmt.Errorf("GetBrokersFromDisk err: %v", e)
log.Println(err)
c.JSONPretty(http.StatusInternalServerError, E(0, err.Error(), "failed"), " ")
return
}
list = true
for _, v := range brokers {
if v.Key == "" || v.Project == "" {
continue
}
item := Item{Key: v.Key, Project: v.Project, Branch: v.Branch}
items = append(items, item)
}
}
if key != "" {
b, e := sse.GetBrokerFromKey(key)
if err != nil {
err = fmt.Errorf("GetBrokerFromKey err: %v", e)
log.Println(err)
c.JSONPretty(http.StatusBadRequest, E(0, err.Error(), "failed"), " ")
}
if b != nil {
project = b.Project
branch = b.Branch
if b.Stored {
stored = true
existmsg = b.GetExistMsg()
}
}
}
p := struct {
Key string
Project string
Branch string
Note string
List bool
Stored bool
ExistMsg string
Items []Item
}{
Key: key,
Project: project,
Branch: branch,
Note: note,
List: list,
Stored: stored,
ExistMsg: existmsg,
Items: items,
}
// Read in the template with our SSE JavaScript code.
t, err := template.New("logs").Parse(box.MustString("logs.html"))
// t, err := template.ParseFiles("web/logs.html")
if err != nil {
log.Fatal("WTF dude, error parsing your template.")
}
// log.Println("parsed template")
// Render the template, writing to `w`.
t.Execute(c.Response(), p)
return
}