early implementation of ari melody LIVE tracker
This commit is contained in:
parent
f7b3faf8e8
commit
9274796729
10 changed files with 335 additions and 39 deletions
31
view/static.go
Normal file
31
view/static.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package view
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func StaticHandler(directory string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
info, err := os.Stat(filepath.Join(directory, filepath.Clean(r.URL.Path)))
|
||||
|
||||
// does the file exist?
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// is thjs a directory? (forbidden)
|
||||
if info.IsDir() {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
http.FileServer(http.Dir(directory)).ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue