http handle angepasst

This commit is contained in:
xoy 2023-01-26 23:47:23 +01:00
parent 320a372b0c
commit b7d75ad5d8
2 changed files with 46 additions and 44 deletions

45
func.go
View File

@ -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 {

45
http.go
View File

@ -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)))
})
}