initial commit

This commit is contained in:
Andre Schaf 2026-03-29 20:46:18 +02:00
commit 1e9f6b7fe0
11 changed files with 482 additions and 0 deletions

49
main.go Normal file
View file

@ -0,0 +1,49 @@
package main
import (
"fmt"
"net/http"
"path/filepath"
)
func main() {
fileServer := http.FileServer(neuteredFs{http.Dir("./static")})
http.Handle("/", fileServer)
err := http.ListenAndServe(":3000", nil)
if err != nil {
fmt.Println(err)
}
}
func (nfs neuteredFs) Open(path string) (http.File, error) {
f, err := nfs.fs.Open(path)
if err != nil {
return nil, err
}
s, err := f.Stat()
if err != nil {
return nil, err
}
if s.IsDir() {
index := filepath.Join(path, "index.html")
if _, err := nfs.fs.Open(index); err != nil {
closeErr := f.Close()
if closeErr != nil {
return nil, closeErr
}
return nil, err
}
}
return f, nil
}
type neuteredFs struct {
fs http.FileSystem
}