basic download functionality

This commit is contained in:
2026-04-11 17:20:21 -06:00
parent 57ff5a0089
commit dc21cc8f5b
2 changed files with 46 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
module gitea.ewpt3ch.dev/ewpt3ch/pkgstash
go 1.26.2
+43
View File
@@ -0,0 +1,43 @@
package main
import (
"log"
"net/http"
"os"
"path/filepath"
)
const repoRoot = "/home/ewpt3ch/dev/pacman-cache-server/tmprepo"
func main() {
const port = "8090"
mux := http.NewServeMux()
mux.HandleFunc("GET /{repo}/os/{arch}/{file}", handlePackage)
httpServe := &http.Server{
Addr: ":" + port,
Handler: mux,
}
log.Fatal(httpServe.ListenAndServe())
}
func handlePackage(w http.ResponseWriter, req *http.Request) {
repo := req.PathValue("repo")
arch := req.PathValue("arch")
file := req.PathValue("file")
filePath := filepath.Join(repoRoot, repo, "os", arch, file)
// is where we handle cache misses and fetch the file
// from a mirror, for now we send a 404
if _, err := os.Stat(filePath); err != nil {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(404)
w.Write([]byte("No such file"))
return
}
http.ServeFile(w, req, filePath)
}