From 1d47646d99e7da71d04c49b0d16bfb21ecf78308 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Thu, 10 Aug 2023 17:02:00 +0200 Subject: Support a custom docs folder path (-f option) --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 91d6fb7..f2aed1f 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ var nonce []byte = nil var db *sql.DB -const baseDocDir string = "docs" +var baseDocDir string = "docs" const NOTFOUND string = "Not found" const UNAUTH string = "Unauthorized" @@ -273,7 +273,7 @@ func index(w http.ResponseWriter, r *http.Request) { file.Name(), humanize(info.Size()), info.ModTime(), - path.Join(baseDocDir, username, file.Name()), + path.Join("/docs/", username, file.Name()), }) } flasherr := consumeFlash(w, r, "error") @@ -635,6 +635,7 @@ func upload(w http.ResponseWriter, r *http.Request) { func main() { p := flag.Int("p", 8080, "the port to bind to") dbPath := flag.String("d", "./db/test.db", "the db to connect to") + docPath := flag.String("f", "docs", "the path of the docs folder") flag.Parse() var err error log.Printf("Connecting to db: %s\n", *dbPath) @@ -644,6 +645,8 @@ func main() { } defer db.Close() + baseDocDir = *docPath + log.Printf("baseDocDir: %s\n", baseDocDir) http.HandleFunc("/docs/", handleFileServer(baseDocDir, "/docs/")) //http.Handle("/docs/", http.StripPrefix("/docs/", http.FileServer(http.Dir("docs")))) http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) -- cgit v1.2.3