Get text files from __files__ dir

This commit is contained in:
Bel LaPointe
2020-07-23 23:21:43 -06:00
parent 461592ec40
commit bbdd4919ba
3 changed files with 94 additions and 1 deletions

29
view/files.go Normal file
View File

@@ -0,0 +1,29 @@
package view
import (
"local/dndex/config"
"local/dndex/storage"
"net/http"
"path"
"strings"
)
func files(_ storage.Graph, w http.ResponseWriter, r *http.Request) error {
r.URL.Path = strings.TrimPrefix(r.URL.Path, config.New().FilePrefix)
if len(r.URL.Path) < 2 {
http.NotFound(w, r)
return nil
}
switch r.Method {
case http.MethodGet:
return filesGet(w, r)
default:
http.NotFound(w, r)
return nil
}
}
func filesGet(w http.ResponseWriter, r *http.Request) error {
http.ServeFile(w, r, path.Join(config.New().FileRoot, r.URL.Path))
return nil
}