/
handlers.go
71 lines (55 loc) · 1.27 KB
/
handlers.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package web
import (
"github.com/labstack/echo"
"net/http"
)
func health(c echo.Context) error {
return c.NoContent(200)
}
func index(ec echo.Context) error {
c := ec.(*context)
index, err := c.backend.GetIndex()
if err != nil {
return err
}
return c.Blob(200, "text/yaml", index)
}
func getChart(ec echo.Context) error {
c := ec.(*context)
name := c.Param("chart")
chart, err := c.backend.GetChart(name)
if err != nil {
return err
}
return c.Blob(200, "application/gzip", chart)
}
func putChart(ec echo.Context) error {
c := ec.(*context)
file, err := c.FormFile("chart")
if err != nil {
return echo.NewHTTPError(http.StatusNotFound, "missing 'chart' param")
}
c.Logger().Infof("putting charts %s", file.Filename)
src, err := file.Open()
if err != nil {
return echo.NewHTTPError(
http.StatusInternalServerError,
"failed opening file when uploading chart")
}
defer src.Close()
err = c.backend.PutChart(file.Filename, src)
if err != nil {
return echo.NewHTTPError(
http.StatusInternalServerError,
"backend failed put chart")
}
return c.NoContent(200)
}
func reindex(ec echo.Context) error {
c := ec.(*context)
err := c.backend.Reindex()
if err != nil {
return echo.NewHTTPError(500, "failed to reindex")
}
return c.NoContent(200)
}