forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_zip.go
36 lines (30 loc) · 843 Bytes
/
version_zip.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
package actions
import (
"fmt"
"io"
"net/http"
"github.com/bketelsen/buffet"
"github.com/gobuffalo/buffalo"
"github.com/gomods/athens/pkg/paths"
"github.com/gomods/athens/pkg/storage"
)
func versionZipHandler(getter storage.Getter) func(c buffalo.Context) error {
return func(c buffalo.Context) error {
sp := buffet.SpanFromContext(c)
sp.SetOperationName("versionZipHandler")
params, err := paths.GetAllParams(c)
if err != nil {
return err
}
version, err := getter.Get(params.Module, params.Version)
if storage.IsNotFoundError(err) {
return c.Error(http.StatusNotFound, fmt.Errorf("%s@%s not found", params.Module, params.Version))
} else if err != nil {
return err
}
defer version.Zip.Close()
c.Response().WriteHeader(http.StatusOK)
_, err = io.Copy(c.Response(), version.Zip)
return err
}
}