From 9d515f20bfec8b64d52d3212c881ba3fcdc2c252 Mon Sep 17 00:00:00 2001 From: xoy Date: Thu, 26 Jan 2023 23:47:23 +0100 Subject: [PATCH] http handle angepasst --- func.go | 45 +++++++++++++++++++++++---------------------- http.go | 45 +++++++++++++++++++++++---------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/func.go b/func.go index 3a82467..bd6ebf4 100644 --- a/func.go +++ b/func.go @@ -10,35 +10,36 @@ import ( func handler() { //Pages - httpHandleFunc("home", "./web/pages/home.html", true, "text/html") - httpHandleFunc("treff", "./web/pages/treff.html", false, "text/html") - httpHandleFunc("events", "./web/pages/events.html", false, "text/html") - httpHandleFunc("about", "./web/pages/about.html", false, "text/html") + httpHandleFunc("", "./web/pages/home.html", "text/html") + httpHandleFunc("home", "./web/pages/home.html", "text/html") + httpHandleFunc("treff", "./web/pages/treff.html", "text/html") + httpHandleFunc("events", "./web/pages/events.html", "text/html") + httpHandleFunc("about", "./web/pages/about.html", "text/html") - httpHandleFunc("kontakt", "./web/pages/kontakt.html", false, "text/html") - httpHandleFunc("kontakt/adresse", "./web/pages/kontakt/adresse.html", false, "text/html") - httpHandleFunc("kontakt/irc", "./web/pages/kontakt/irc.html", false, "text/html") - httpHandleFunc("kontakt/mail", "./web/pages/kontakt/mail.html", false, "text/html") - httpHandleFunc("kontakt/tel", "./web/pages/kontakt/tel.html", false, "text/html") + httpHandleFunc("kontakt", "./web/pages/kontakt.html", "text/html") + httpHandleFunc("kontakt/adresse", "./web/pages/kontakt/adresse.html", "text/html") + httpHandleFunc("kontakt/irc", "./web/pages/kontakt/irc.html", "text/html") + httpHandleFunc("kontakt/mail", "./web/pages/kontakt/mail.html", "text/html") + httpHandleFunc("kontakt/tel", "./web/pages/kontakt/tel.html", "text/html") - httpHandleFunc("verein", "./web/pages/verein.html", false, "text/html") - httpHandleFunc("support", "./web/pages/support.html", false, "text/html") + httpHandleFunc("verein", "./web/pages/verein.html", "text/html") + httpHandleFunc("support", "./web/pages/support.html", "text/html") - httpHandleFunc("impressum", "./web/pages/impressum.html", false, "text/html") - httpHandleFunc("datenschutz", "./web/pages/datenschutz.html", false, "text/html") + httpHandleFunc("impressum", "./web/pages/impressum.html", "text/html") + httpHandleFunc("datenschutz", "./web/pages/datenschutz.html", "text/html") //Styles - httpHandleFunc("style/main.css", "./web/styles/main.css", false, "text/css") - httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", false, "text/css") - httpHandleFunc("style/home.css", "./web/styles/home.css", false, "text/css") + httpHandleFunc("style/main.css", "./web/styles/main.css", "text/css") + httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", "text/css") + httpHandleFunc("style/home.css", "./web/styles/home.css", "text/css") //Images - httpHandleFunc("image/logo_ctdo.svg", "./web/images/logo_ctdo.svg", false, "image/svg+xml") - httpHandleFunc("image/header.jpg", "./web/images/header.jpg", false, "image/jpeg") - httpHandleFunc("image/adresse_knopf.webp", "./web/images/adresse_knopf.webp", false, "image/webp") - httpHandleFunc("image/chat_knopf.webp", "./web/images/chat_knopf.webp", false, "image/webp") - httpHandleFunc("image/mail_knopf.webp", "./web/images/mail_knopf.webp", false, "image/webp") - httpHandleFunc("image/tel_knopf.webp", "./web/images/tel_knopf.webp", false, "image/webp") + httpHandleFunc("image/logo_ctdo.svg", "./web/images/logo_ctdo.svg", "image/svg+xml") + httpHandleFunc("image/header.jpg", "./web/images/header.jpg", "image/jpeg") + httpHandleFunc("image/adresse_knopf.webp", "./web/images/adresse_knopf.webp", "image/webp") + httpHandleFunc("image/chat_knopf.webp", "./web/images/chat_knopf.webp", "image/webp") + httpHandleFunc("image/mail_knopf.webp", "./web/images/mail_knopf.webp", "image/webp") + httpHandleFunc("image/tel_knopf.webp", "./web/images/tel_knopf.webp", "image/webp") } func getPages() [][]string { diff --git a/http.go b/http.go index b87456e..81f6a83 100644 --- a/http.go +++ b/http.go @@ -1,31 +1,32 @@ package main import ( - "fmt" "io" "net/http" ) -func httpHandleFunc(urlPath string, filepath string, isMainpage bool, contentType string) { - if isMainpage { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - w.Header().Add("Content-Type", contentType) - io.WriteString(w, htmlReplacer(fileRead(filepath))) - }) - } else { - s := new(submit) - s.data = "null" - http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) { - if r.Method == "POST" { - if err := r.ParseForm(); err != nil { - fmt.Fprintf(w, "ParseForm() err: %v", err) - return - } - } +func httpHandleFunc(urlPath string, filepath string, contentType string) { + s := new(submit) + s.data = "null" + http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", contentType) - w.Header().Add("Content-Type", contentType) - - io.WriteString(w, htmlReplacer(fileRead(filepath))) - }) - } + io.WriteString(w, htmlReplacer(fileRead(filepath))) + }) +} + +func httpHandleFuncWithPOST(urlPath string, filepath string, contentType string) { + s := new(submit) + s.data = "null" + http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) { + if r.Method == "POST" { + if err := r.ParseForm(); err != nil { + panic(err) + } + } + + w.Header().Add("Content-Type", contentType) + + io.WriteString(w, htmlReplacer(fileRead(filepath))) + }) }