For better code organisation the entire Codebase has been restructured and cleaned up. handlers have been separated into an own package, as well as the model.
33 lines
819 B
Go
33 lines
819 B
Go
package main
|
|
|
|
import (
|
|
"ddServer/handlers"
|
|
"ddServer/model"
|
|
"embed"
|
|
"fmt"
|
|
"net/http"
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
mu sync.Mutex
|
|
chars []model.Character
|
|
//go:embed templates/*.html
|
|
//go:embed images/*
|
|
content embed.FS
|
|
Monsters []model.Monster
|
|
)
|
|
|
|
func main() {
|
|
filename := ""
|
|
|
|
http.HandleFunc("/", handlers.FormHandler(content, filename))
|
|
http.HandleFunc("/submit", handlers.SubmitHandler(content, &chars, &Monsters, filename))
|
|
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.FS(content))))
|
|
http.HandleFunc("/addMonster", handlers.AddMonster(&Monsters))
|
|
http.HandleFunc("/about", handlers.AboutHandler(content))
|
|
http.HandleFunc("/contact", handlers.ContactHandler(content))
|
|
|
|
fmt.Println("Server gestartet, erreichbar unter http://localhost:8080")
|
|
http.ListenAndServe(":8080", nil)
|
|
}
|