aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2023-08-10 17:02:00 +0200
committerJulian Hurst <ark@mansus.space>2023-08-10 17:02:00 +0200
commit1d47646d99e7da71d04c49b0d16bfb21ecf78308 (patch)
tree0d5f3950ded04ad6ff83335050481bbbb519ffa8 /main.go
parente0444c96749d016b003443087481c67592a4893d (diff)
downloaddocspace-1d47646d99e7da71d04c49b0d16bfb21ecf78308.tar.gz
Support a custom docs folder path (-f option)
Diffstat (limited to 'main.go')
-rw-r--r--main.go7
1 files changed, 5 insertions, 2 deletions
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"))))