backend: frontend: cleaned up the codebase and added more logging for debuging
This commit is contained in:
parent
faf7c2f782
commit
3a77eb1593
11 changed files with 152 additions and 38 deletions
19
main.go
19
main.go
|
|
@ -20,10 +20,14 @@ var (
|
|||
Monsters []model.Monster
|
||||
)
|
||||
|
||||
// main is the entry point of the program.
|
||||
func main() {
|
||||
filename := ""
|
||||
|
||||
// Print the message indicating that 'static' has been included.
|
||||
log.Printf("Eingebunden is %v\n", static)
|
||||
|
||||
// Set up the HTTP handlers for different routes.
|
||||
http.HandleFunc("/", handlers.FormHandler(content, &Monsters, filename))
|
||||
http.HandleFunc("/submit", handlers.SubmitHandler(content, &chars, &Monsters, filename))
|
||||
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.FS(content))))
|
||||
|
|
@ -33,27 +37,34 @@ func main() {
|
|||
http.HandleFunc("/contact", handlers.ContactHandler(content))
|
||||
http.HandleFunc("/monsterTable", handlers.MonsterTableHandler(content, &Monsters))
|
||||
|
||||
// Lade die CSS-Datei
|
||||
// Load the CSS file.
|
||||
css, err := loadCSS(static)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Füge eine Route für die CSS-Datei hinzu
|
||||
// Add a route for the CSS file.
|
||||
http.HandleFunc("/static/darkly_bulmawatch.css", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/css")
|
||||
w.Write([]byte(css))
|
||||
})
|
||||
|
||||
// Print the message indicating that the server has started.
|
||||
log.Print("Server gestartet, erreichbar unter http://localhost:8080")
|
||||
http.ListenAndServe(":8080", nil)
|
||||
|
||||
// Start the server and listen for incoming requests on port 8080.
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
|
||||
// loadCSS liest die CSS-Datei aus dem eingebetteten Dateisystem.
|
||||
// loadCSS reads the CSS file from the embedded filesystem.
|
||||
// It takes the content embed.FS as input.
|
||||
// It returns the content of the CSS file as a string and an error if any.
|
||||
func loadCSS(content embed.FS) (string, error) {
|
||||
// Read the CSS file "static/darkly_bulmawatch.css" from the embedded filesystem
|
||||
file, err := content.ReadFile("static/darkly_bulmawatch.css")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// Convert the file content to a string and return
|
||||
return string(file), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue