intal commit

This commit is contained in:
2025-08-14 22:39:08 +02:00
parent 9b555c2637
commit 84bc80d921
14 changed files with 182 additions and 0 deletions

35
main.go Normal file
View File

@@ -0,0 +1,35 @@
package main
import (
"encoding/json"
"net/http"
"os"
"strings"
)
func main() {
http.HandleFunc("/files", func(w http.ResponseWriter, r *http.Request) {
files, err := os.ReadDir("./static")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var names []string
for _, f := range files {
name := f.Name()
if strings.HasSuffix(name, ".jpg") || strings.HasSuffix(name, ".png") || strings.HasSuffix(name, ".gif") {
names = append(names, name)
}
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(names)
})
fs := http.FileServer(http.Dir("./static"))
http.Handle("/", fs)
http.ListenAndServe(":8080", nil)
}