ctdo.de/func.go

119 lines
3.8 KiB
Go

package main
import (
"io"
"net/http"
"strconv"
"strings"
"time"
)
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("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("verein", "./web/pages/verein.html", false, "text/html")
httpHandleFunc("support", "./web/pages/support.html", false, "text/html")
httpHandleFunc("impressum", "./web/pages/impressum.html", false, "text/html")
httpHandleFunc("datenschutz", "./web/pages/datenschutz.html", false, "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")
//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")
}
func getPages() [][]string {
output := [][]string{}
output = append(output, []string{"home", "/home"})
output = append(output, []string{"zeiten & location", "/treff"})
output = append(output, []string{"events", "/events"})
output = append(output, []string{"über uns", "/about"})
output = append(output, []string{"kontakt", "/kontakt"})
output = append(output, []string{"verein", "/verein"})
output = append(output, []string{"unterstützung", "/support"})
return output
}
func getFooterPages() [][]string {
output := [][]string{}
output = append(output, []string{"impressum", "/impressum"})
output = append(output, []string{"datenschutzerklärung", "/datenschutz"})
return output
}
func getRoomState() status {
c := &http.Client{Timeout: 10 * time.Second}
r, err := c.Get("https://status.ctdo.de/api/simple/v2")
if err != nil {
panic(err)
}
defer r.Body.Close()
body, _err := io.ReadAll(r.Body)
if _err != nil {
panic(_err)
}
bodyString := string(body)
temp := []string{}
bodyString = strings.ReplaceAll(bodyString, "{", "")
bodyString = strings.ReplaceAll(bodyString, "}", "")
_temp := strings.Split(bodyString, ",")
for _, element := range _temp {
__temp := strings.Split(element, ":")
temp = append(temp, __temp[1])
}
roomState := new(status)
roomState.state = temp[0] == "true"
var __err error
roomState.power, __err = strconv.ParseInt(temp[2], 0, 64)
if __err != nil {
panic(__err)
}
return *roomState
}
func htmlReplacer(input string) string {
output := strings.ReplaceAll(input, "!NAV", htmlNav(getPages()))
if getRoomState().state {
output = strings.ReplaceAll(output, "!RAUMSTATUS", "<p>Raumstatus: <b class=\"green-text\">offen</b></p>")
} else {
output = strings.ReplaceAll(output, "!RAUMSTATUS", "<p>Raumstatus: <b class=\"red-text\">geschlossen</b></p>")
}
output = strings.ReplaceAll(output, "!FOOTERNAV", htmlNav(getFooterPages()))
return output
}