aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/handler')
-rw-r--r--pkg/handler/git/handler.go28
-rw-r--r--pkg/handler/router.go2
2 files changed, 12 insertions, 18 deletions
diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go
index aed9917..8bb4002 100644
--- a/pkg/handler/git/handler.go
+++ b/pkg/handler/git/handler.go
@@ -39,7 +39,7 @@ type (
GetAbout(name string) (string, error)
ListTags(name string) ([]*plumbing.Reference, error)
ListBranches(name string) ([]*plumbing.Reference, error)
- WriteTarGZip(w io.Writer, name, ref, filename string) error
+ WriteTarGZip(w io.Writer, name, ref, prefix string) error
}
configurationRepository interface {
@@ -91,30 +91,24 @@ func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) error {
func (g *GitHandler) Archive(w http.ResponseWriter, r *http.Request) error {
ext.SetGZip(w)
name := r.PathValue("name")
- refs := r.PathValue("refs")
- ref := strings.TrimSuffix(refs, ".tar.gz")
+ file := r.PathValue("file")
+ ref := strings.TrimSuffix(file, ".tar.gz")
// TODO: remove it once we can support more than gzip
- if !strings.HasSuffix(refs, ".tar.gz") {
+ if !strings.HasSuffix(file, ".tar.gz") {
ext.NotFound(w)
return nil
}
- filenameWithExt := fmt.Sprintf("%s-%s.tar.gz", name, ref)
- ext.SetFileName(w, filenameWithExt)
- filename := fmt.Sprintf("%s-%s", name, ref)
+ filename := fmt.Sprintf("%s-%s.tar.gz", name, ref)
+ ext.SetFileName(w, filename)
- // writing to a buffer so we can run all the process before writing error
- var buf bytes.Buffer
- err := g.gitService.WriteTarGZip(&buf, name, ref, filename)
+ prefix := fmt.Sprintf("%s-%s", name, ref)
+ err := g.gitService.WriteTarGZip(w, name, ref, prefix)
if err != nil {
- return err
- }
-
- // since that has write to w it cannot return a error.
- _, err = io.Copy(w, &buf)
- if err != nil {
- slog.Error("Error copying buffer", "error", err)
+ // once we start writing to the body we can't report error anymore
+ // so we are only left with printing the error.
+ slog.Error("Error generating tar gzip file", "error", err)
}
return nil
diff --git a/pkg/handler/router.go b/pkg/handler/router.go
index 2293ab6..6ee7ba3 100644
--- a/pkg/handler/router.go
+++ b/pkg/handler/router.go
@@ -41,7 +41,7 @@ func MountHandler(
mux.HandleFunc("/{name}/tree/{ref}/{rest...}", gitHandler.Tree)
mux.HandleFunc("/{name}/blob/{ref}/{rest...}", gitHandler.Blob)
mux.HandleFunc("/{name}/log/{ref}/", gitHandler.Log)
- mux.HandleFunc("/{name}/archive/{refs...}", gitHandler.Archive)
+ mux.HandleFunc("/{name}/archive/{file}", gitHandler.Archive)
mux.HandleFunc("/config", configHandler)
mux.HandleFunc("/about", aboutHandler.About)
mux.HandleFunc("/", gitHandler.List)