added logging
This commit is contained in:
parent
a408e1487d
commit
2d3f1ef951
6 changed files with 9 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func AboutHandler(content embed.FS) http.HandlerFunc {
|
func AboutHandler(content embed.FS) http.HandlerFunc {
|
||||||
|
log.Print("AboutHandler called")
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl, err := template.ParseFS(content, "templates/base.html", "templates/header.html", "templates/main.html", "templates/footer.html", "templates/about.html")
|
tmpl, err := template.ParseFS(content, "templates/base.html", "templates/header.html", "templates/main.html", "templates/footer.html", "templates/about.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,13 @@ package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ddServer/model"
|
"ddServer/model"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddMonster(Monsters *[]model.Monster) http.HandlerFunc {
|
func AddMonster(Monsters *[]model.Monster) http.HandlerFunc {
|
||||||
|
log.Print("AddMonster called")
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// TODO
|
// TODO
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func ContactHandler(content embed.FS) http.HandlerFunc {
|
func ContactHandler(content embed.FS) http.HandlerFunc {
|
||||||
|
log.Print("ContactHandler called")
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl, err := template.ParseFS(content, "templates/base.html", "templates/header.html", "templates/main.html", "templates/footer.html", "templates/about.html", "templates/contact.html")
|
tmpl, err := template.ParseFS(content, "templates/base.html", "templates/header.html", "templates/main.html", "templates/footer.html", "templates/about.html", "templates/contact.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func FormHandler(content embed.FS, filename string) http.HandlerFunc {
|
func FormHandler(content embed.FS, filename string) http.HandlerFunc {
|
||||||
|
log.Print("FormHandler called")
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl, err := template.ParseFS(content, "templates/base.html", "templates/header.html", "templates/main.html", "templates/footer.html", "templates/monsterForm.html")
|
tmpl, err := template.ParseFS(content, "templates/base.html", "templates/header.html", "templates/main.html", "templates/footer.html", "templates/monsterForm.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -14,6 +15,7 @@ var mu sync.Mutex
|
||||||
|
|
||||||
// submitHandler verarbeitet die Formulardaten
|
// submitHandler verarbeitet die Formulardaten
|
||||||
func SubmitHandler(content embed.FS, chars *[]model.Character, Monsters *[]model.Monster, filename string) http.HandlerFunc {
|
func SubmitHandler(content embed.FS, chars *[]model.Character, Monsters *[]model.Monster, filename string) http.HandlerFunc {
|
||||||
|
log.Print("SubmitHandler called")
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
|
|
||||||
4
main.go
4
main.go
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"ddServer/handlers"
|
"ddServer/handlers"
|
||||||
"ddServer/model"
|
"ddServer/model"
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
@ -28,6 +28,6 @@ func main() {
|
||||||
http.HandleFunc("/about", handlers.AboutHandler(content))
|
http.HandleFunc("/about", handlers.AboutHandler(content))
|
||||||
http.HandleFunc("/contact", handlers.ContactHandler(content))
|
http.HandleFunc("/contact", handlers.ContactHandler(content))
|
||||||
|
|
||||||
fmt.Println("Server gestartet, erreichbar unter http://localhost:8080")
|
log.Print("Server gestartet, erreichbar unter http://localhost:8080")
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue