-
Notifications
You must be signed in to change notification settings - Fork 21
/
dashboard.go
56 lines (44 loc) · 1.38 KB
/
dashboard.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
50
51
52
53
54
55
56
package dashboard
import (
"encoding/json"
"fmt"
"net/http"
"github.com/jekyll/dashboard/triage"
)
var defaultPort = 8000
func jsonResponse(w http.ResponseWriter, code int, body string) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(code)
w.Write([]byte(body))
}
func reset(w http.ResponseWriter, r *http.Request) {
resetProjects()
jsonResponse(w, http.StatusOK, `{"reset": "true"}`)
}
func show(w http.ResponseWriter, r *http.Request) {
name := r.FormValue("name")
if name == "" {
jsonResponse(w, http.StatusBadRequest, `{"error": "missing name param"}`)
return
}
proj := getProject(name)
if proj == nil {
jsonResponse(w, http.StatusNotFound, fmt.Sprintf(`{"error": "could not find project '%s'"}`, name))
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(getProject(name))
}
func index(w http.ResponseWriter, r *http.Request) {
indexTmpl.Execute(w, templateInfo{Projects: getProjects()})
}
func Listen(bindAddr string) error {
// Replace init()'s with explicit inline initializations
githubClient = newGitHubClient()
initProjects()
http.HandleFunc("/reset.json", reset)
http.HandleFunc("/show.json", show)
http.Handle("/triage", triage.New(githubClient, []string{"documentation", "bug", "enhancement"}))
http.HandleFunc("/", index)
return http.ListenAndServe(bindAddr, nil)
}