Initial commit
This commit is contained in:
commit
1cc55d91ef
7 changed files with 912 additions and 0 deletions
41
main.go
Normal file
41
main.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"isosilo/internal/handlers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dir := flag.String("dir", ".", "Directory containing ISO files to serve")
|
||||
addr := flag.String("addr", ":8080", "Address to listen on")
|
||||
flag.Parse()
|
||||
|
||||
info, err := os.Stat(*dir)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot access directory %q: %v", *dir, err)
|
||||
}
|
||||
if !info.IsDir() {
|
||||
log.Fatalf("%q is not a directory", *dir)
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
h := handlers.New(*dir)
|
||||
|
||||
// Routes:
|
||||
// GET / → list all ISOs in the directory
|
||||
// GET /browse/{iso} → list root of ISO
|
||||
// GET /browse/{iso}/{path...} → list directory inside ISO
|
||||
// GET /file/{iso}/{path...} → download a file from inside ISO
|
||||
mux.HandleFunc("/", h.ListISOs)
|
||||
mux.HandleFunc("/browse/", h.BrowseISO)
|
||||
mux.HandleFunc("/file/", h.DownloadFile)
|
||||
|
||||
fmt.Printf("ISOSilo listening on %s\n", *addr)
|
||||
fmt.Printf("Serving ISOs from: %s\n", *dir)
|
||||
log.Fatal(http.ListenAndServe(*addr, mux))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue