added refresh db capability and did some refactoring

This commit is contained in:
2026-04-14 22:46:23 -06:00
parent 36f856cb25
commit 5687f7f992
5 changed files with 70 additions and 33 deletions
+12 -7
View File
@@ -7,20 +7,25 @@ import (
"gitea.ewpt3ch.dev/ewpt3ch/pkgstash/internal/cache"
)
const repoRoot = "/home/ewpt3ch/dev/pacman-cache-server/tmprepo"
type Server struct {
cfg *Config
c *cache.Cache
}
func main() {
const port = "8090"
cfg := NewConfig()
c := cache.NewCache(cfg.RepoPath, cfg.MirrorURL)
c := cache.NewCache(cfg.MirrorRoot, cfg.MirrorURL)
srv := &Server{cfg: cfg, c: c}
mux := http.NewServeMux()
mux.HandleFunc("GET /{repo}/os/{arch}/{file}", func(w http.ResponseWriter, req *http.Request) {
handlePackage(w, req, c)
})
mux.HandleFunc("GET /{repo}/os/{arch}/{file}", srv.handlePackage)
if err := srv.c.Refresh(); err != nil {
log.Fatal(err)
}
httpServe := &http.Server{
Addr: ":" + port,
Addr: ":" + srv.cfg.Port,
Handler: mux,
}