135 lines
3.6 KiB
Go
135 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
/*
|
|
|
|
Timezone = UTC
|
|
|
|
*/
|
|
|
|
func main() {
|
|
addr := readHttpYML()
|
|
|
|
logger("----------------START----------------")
|
|
logger("timezone = UTC")
|
|
logger("connection open with address " + addr)
|
|
|
|
handler()
|
|
|
|
err := http.ListenAndServe(addr, nil)
|
|
errorPanic(err)
|
|
|
|
defer logger("----------------END----------------")
|
|
}
|
|
|
|
func handler() {
|
|
logger("----------------HANDLE PAGES----------------")
|
|
|
|
//pages
|
|
httpHandleFunc("", "./web/pages/home.html", "text/html")
|
|
handleFilesInFolder("", "./web/pages/", true)
|
|
|
|
//admin pages
|
|
keys := getAdminKeys()
|
|
if len(keys) > 0 {
|
|
for _, key := range keys {
|
|
httpHandleFunc("admin/"+key, "./web/pages/admin/dashboard.html", "text/html")
|
|
httpHandleFuncWithPOST("admin/"+key+"/addEvent", "./web/pages/admin/dashboard.html", "text/html")
|
|
}
|
|
}
|
|
|
|
//styles
|
|
handleFilesInFolder("style/", "./web/styles/", false)
|
|
|
|
//images
|
|
handleFilesInFolder("image/", "./web/images/", false)
|
|
logger("----------------HANDLE END----------------")
|
|
}
|
|
|
|
var alreadyHandledFiles []string = []string{"./web/pages/admin/dashboard.html"}
|
|
|
|
func handleFilesInFolder(urlPrefix string, folderpath string, handleWithoutFileSuffix bool) {
|
|
if folderpath[len(folderpath)-1] != '/' {
|
|
folderpath += "/"
|
|
}
|
|
files, err := ioutil.ReadDir(folderpath)
|
|
errorPanic(err)
|
|
|
|
for _, file := range files {
|
|
alreadyHandled := stringListContains(alreadyHandledFiles, folderpath+file.Name())
|
|
|
|
if !alreadyHandled {
|
|
if !file.IsDir() {
|
|
f := strings.Split(file.Name(), ".")
|
|
ContentType := f[len(f)-1]
|
|
filename := ""
|
|
|
|
if handleWithoutFileSuffix {
|
|
for index, item := range f {
|
|
if index < len(f)-1 {
|
|
filename += item
|
|
}
|
|
}
|
|
} else {
|
|
filename = file.Name()
|
|
}
|
|
|
|
switch ContentType {
|
|
case "png":
|
|
httpHandleFunc(urlPrefix+filename, folderpath+file.Name(), "image/png")
|
|
case "webp":
|
|
httpHandleFunc(urlPrefix+filename, folderpath+file.Name(), "image/webp")
|
|
case "svg":
|
|
httpHandleFunc(urlPrefix+filename, folderpath+file.Name(), "image/svg+xml")
|
|
case "jpeg":
|
|
httpHandleFunc(urlPrefix+filename, folderpath+file.Name(), "image/jpeg")
|
|
case "jpg":
|
|
httpHandleFunc(urlPrefix+filename, folderpath+file.Name(), "image/jpeg")
|
|
case "gif":
|
|
httpHandleFunc(urlPrefix+filename, folderpath+file.Name(), "image/gif")
|
|
case "css":
|
|
httpHandleFunc(urlPrefix+filename, folderpath+file.Name(), "text/css")
|
|
case "html":
|
|
httpHandleFunc(urlPrefix+filename, folderpath+file.Name(), "text/html")
|
|
default:
|
|
logger("handleFilesInFolder -> content-type unknown : " + folderpath + file.Name())
|
|
}
|
|
alreadyHandledFiles = append(alreadyHandledFiles, folderpath+file.Name())
|
|
} else {
|
|
childFolder := file.Name()
|
|
handleFilesInFolder(childFolder, folderpath+childFolder, handleWithoutFileSuffix)
|
|
}
|
|
} else {
|
|
logger("handleFilesInFolder -> already handled : " + folderpath + file.Name())
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|