Convert to go

This commit is contained in:
2026-07-30 00:30:27 +02:00
parent 42fb4e90b4
commit 4518a4a363
35 changed files with 962 additions and 1797 deletions
+35
View File
@@ -0,0 +1,35 @@
package routes
import (
"encoding/json"
"net/http"
"list_app/controllers"
"list_app/public"
"list_app/web"
)
func New() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("GET /{$}", web.Index)
mux.HandleFunc("POST /add", web.Add)
mux.HandleFunc("GET /api", apiIndex)
mux.HandleFunc("GET /api/{$}", apiIndex)
mux.HandleFunc("GET /api/media/{mediaType}", controllers.List)
// Poster images are fetched at runtime, so they're served from a real
// directory on disk rather than the embedded static assets below.
mux.Handle("/poster/", http.StripPrefix("/poster/", http.FileServer(http.Dir(controllers.PostersDir))))
mux.Handle("/", http.FileServerFS(public.FS))
return mux
}
func apiIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"message": "API is working"})
}