anpassung der funktions- und variablennamen, erstellung vorübergehender README.md

This commit is contained in:
xoy 2023-01-26 23:13:44 +01:00
parent 28ae77931a
commit 02840b07de
6 changed files with 75 additions and 70 deletions

View File

@ -1 +1,5 @@
# Readme
# Readme
git clone https://git.ctdo.de/xoy/ctdo.de.git
cd ./ctdo.de/
go run .

View File

@ -5,7 +5,7 @@ import (
"log"
)
func file_read(src string) string {
func fileRead(src string) string {
content, err := ioutil.ReadFile(src)
if err != nil {

58
func.go
View File

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

30
html.go
View File

@ -1,44 +1,28 @@
package main
import "strings"
func html_Element(tag string, innerHTML string, args string) string {
func htmlElement(tag string, innerHTML string, args string) string {
return "<" + tag + " " + args + ">" + innerHTML + "</" + tag + ">"
}
func html_LinkElement(innerHTML string, destination string, blank bool, args string) string {
func htmlLinkElement(innerHTML string, destination string, blank bool, args string) string {
b := ""
if blank {
b = "target=\"_blank\""
}
return html_Element("a", innerHTML, " href=\""+destination+"\" "+b)
return htmlElement("a", innerHTML, " href=\""+destination+"\" "+b)
}
func html_InputElement(name string, _type string, value string, args string) string {
func htmlInputElement(name string, _type string, value string, args string) string {
return "<input name=\"" + name + "\" type=\"" + _type + "\" value=\"" + value + "\" " + args + ">"
}
func html_Nav(pages [][]string) string {
func htmlNav(pages [][]string) string {
output := ""
for _, page := range pages {
output += html_Element("li", html_LinkElement(page[0], page[1], false, ""), "")
output += htmlElement("li", htmlLinkElement(page[0], page[1], false, ""), "")
}
return html_Element("nav", html_Element("ul", output, ""), "")
}
func html_replacer(input string) string {
output := strings.ReplaceAll(input, "!NAV", html_Nav(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", html_Nav(getFooterPages()))
return output
return htmlElement("nav", htmlElement("ul", output, ""), "")
}

29
http.go
View File

@ -1,23 +1,21 @@
package main
import (
"errors"
"fmt"
"io"
"net/http"
"os"
)
func http_HandleFunc(url_path string, filepath string, is_mainpage bool, content_type string) {
if is_mainpage {
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", content_type)
io.WriteString(w, html_replacer(file_read(filepath)))
w.Header().Add("Content-Type", contentType)
io.WriteString(w, htmlReplacer(fileRead(filepath)))
})
} else {
s := new(submit)
s.data = "null"
http.HandleFunc("/"+url_path, func(w http.ResponseWriter, r *http.Request) {
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)
@ -25,22 +23,9 @@ func http_HandleFunc(url_path string, filepath string, is_mainpage bool, content
}
}
w.Header().Add("Content-Type", content_type)
w.Header().Add("Content-Type", contentType)
io.WriteString(w, html_replacer(file_read(filepath)))
io.WriteString(w, htmlReplacer(fileRead(filepath)))
})
}
}
func http_start(address string) { // address could be = ":8080"
handler()
err := http.ListenAndServe(address, nil)
if errors.Is(err, http.ErrServerClosed) {
fmt.Printf("server closed\n")
} else if err != nil {
fmt.Printf("error starting server: %s\n", err)
os.Exit(1)
}
}

20
main.go
View File

@ -1,5 +1,23 @@
package main
import (
"errors"
"fmt"
"net/http"
"os"
)
func main() {
http_start(":80")
addr := ":80"
handler()
err := http.ListenAndServe(addr, nil)
if errors.Is(err, http.ErrServerClosed) {
fmt.Printf("server closed\n")
} else if err != nil {
fmt.Printf("error starting server: %s\n", err)
os.Exit(1)
}
}