43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
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...} → stream/view a file from inside ISO
|
|
// GET /raw/{filename} → serve raw disk files (ISOs, covers, descriptions)
|
|
mux.HandleFunc("/", h.ListISOs)
|
|
mux.HandleFunc("/browse/", h.BrowseISO)
|
|
mux.HandleFunc("/file/", h.DownloadFile)
|
|
mux.HandleFunc("/raw/", h.RawFile)
|
|
|
|
fmt.Printf("ISOSilo listening on %s\n", *addr)
|
|
fmt.Printf("Serving ISOs from: %s\n", *dir)
|
|
log.Fatal(http.ListenAndServe(*addr, mux))
|
|
}
|