Get text files from __files__ dir
This commit is contained in:
29
view/files.go
Normal file
29
view/files.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user