func (r *Registry) HandlePkgDownload(repo *git.Repository,
	w http.ResponseWriter, req *http.Request) error {
	version := req.URL.Query().Get(":version")
	id, err := git.NewOid(version)
	if err != nil || id == nil {
		code := http.StatusBadRequest
		res := &util.ErrorResponse{
			http.StatusText(code),
			"version is not a valid git object id",
		}
		return util.RespondJSON(w, code, res)
	}
	d, err := storage.NewDownload(repo, id)
	if err != nil || d == nil {
		if gitErr, ok := err.(*git.GitError); !ok ||
			gitErr.Class != git.ErrClassOdb {
			return err
		}
		code := http.StatusNotFound
		res := &util.ErrorResponse{
			http.StatusText(code),
			"package not found",
		}
		return util.RespondJSON(w, code, res)
	}
	return d.Start(w)
}
HandlePkgDownload handles package downloads.
package registry
import (
	"github.com/alexanderGugel/nerva/storage"
	"github.com/alexanderGugel/nerva/util"
	"github.com/libgit2/git2go"
	"net/http"
)