http handle angepasst

This commit is contained in:
xoy 2023-01-26 23:47:23 +01:00
parent 0af5f44035
commit 9d515f20bf
2 changed files with 46 additions and 44 deletions

45
func.go
View File

@ -10,35 +10,36 @@ import (
func handler() { func handler() {
//Pages //Pages
httpHandleFunc("home", "./web/pages/home.html", true, "text/html") httpHandleFunc("", "./web/pages/home.html", "text/html")
httpHandleFunc("treff", "./web/pages/treff.html", false, "text/html") httpHandleFunc("home", "./web/pages/home.html", "text/html")
httpHandleFunc("events", "./web/pages/events.html", false, "text/html") httpHandleFunc("treff", "./web/pages/treff.html", "text/html")
httpHandleFunc("about", "./web/pages/about.html", false, "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", "./web/pages/kontakt.html", "text/html")
httpHandleFunc("kontakt/adresse", "./web/pages/kontakt/adresse.html", false, "text/html") httpHandleFunc("kontakt/adresse", "./web/pages/kontakt/adresse.html", "text/html")
httpHandleFunc("kontakt/irc", "./web/pages/kontakt/irc.html", false, "text/html") httpHandleFunc("kontakt/irc", "./web/pages/kontakt/irc.html", "text/html")
httpHandleFunc("kontakt/mail", "./web/pages/kontakt/mail.html", false, "text/html") httpHandleFunc("kontakt/mail", "./web/pages/kontakt/mail.html", "text/html")
httpHandleFunc("kontakt/tel", "./web/pages/kontakt/tel.html", false, "text/html") httpHandleFunc("kontakt/tel", "./web/pages/kontakt/tel.html", "text/html")
httpHandleFunc("verein", "./web/pages/verein.html", false, "text/html") httpHandleFunc("verein", "./web/pages/verein.html", "text/html")
httpHandleFunc("support", "./web/pages/support.html", false, "text/html") httpHandleFunc("support", "./web/pages/support.html", "text/html")
httpHandleFunc("impressum", "./web/pages/impressum.html", false, "text/html") httpHandleFunc("impressum", "./web/pages/impressum.html", "text/html")
httpHandleFunc("datenschutz", "./web/pages/datenschutz.html", false, "text/html") httpHandleFunc("datenschutz", "./web/pages/datenschutz.html", "text/html")
//Styles //Styles
httpHandleFunc("style/main.css", "./web/styles/main.css", false, "text/css") httpHandleFunc("style/main.css", "./web/styles/main.css", "text/css")
httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", false, "text/css") httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", "text/css")
httpHandleFunc("style/home.css", "./web/styles/home.css", false, "text/css") httpHandleFunc("style/home.css", "./web/styles/home.css", "text/css")
//Images //Images
httpHandleFunc("image/logo_ctdo.svg", "./web/images/logo_ctdo.svg", false, "image/svg+xml") httpHandleFunc("image/logo_ctdo.svg", "./web/images/logo_ctdo.svg", "image/svg+xml")
httpHandleFunc("image/header.jpg", "./web/images/header.jpg", false, "image/jpeg") httpHandleFunc("image/header.jpg", "./web/images/header.jpg", "image/jpeg")
httpHandleFunc("image/adresse_knopf.webp", "./web/images/adresse_knopf.webp", false, "image/webp") httpHandleFunc("image/adresse_knopf.webp", "./web/images/adresse_knopf.webp", "image/webp")
httpHandleFunc("image/chat_knopf.webp", "./web/images/chat_knopf.webp", false, "image/webp") httpHandleFunc("image/chat_knopf.webp", "./web/images/chat_knopf.webp", "image/webp")
httpHandleFunc("image/mail_knopf.webp", "./web/images/mail_knopf.webp", false, "image/webp") httpHandleFunc("image/mail_knopf.webp", "./web/images/mail_knopf.webp", "image/webp")
httpHandleFunc("image/tel_knopf.webp", "./web/images/tel_knopf.webp", false, "image/webp") httpHandleFunc("image/tel_knopf.webp", "./web/images/tel_knopf.webp", "image/webp")
} }
func getPages() [][]string { func getPages() [][]string {

17
http.go
View File

@ -1,25 +1,27 @@
package main package main
import ( import (
"fmt"
"io" "io"
"net/http" "net/http"
) )
func httpHandleFunc(urlPath string, filepath string, isMainpage bool, contentType string) { func httpHandleFunc(urlPath string, filepath string, contentType string) {
if isMainpage { s := new(submit)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 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)))
}) })
} else { }
func httpHandleFuncWithPOST(urlPath string, filepath string, contentType string) {
s := new(submit) s := new(submit)
s.data = "null" s.data = "null"
http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" { if r.Method == "POST" {
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ParseForm() err: %v", err) panic(err)
return
} }
} }
@ -28,4 +30,3 @@ func httpHandleFunc(urlPath string, filepath string, isMainpage bool, contentTyp
io.WriteString(w, htmlReplacer(fileRead(filepath))) io.WriteString(w, htmlReplacer(fileRead(filepath)))
}) })
} }
}