ctdo.de/http.go

56 lines
1.7 KiB
Go
Raw Normal View History

package main
import (
"io"
"net/http"
2023-01-28 22:18:28 +00:00
"strings"
)
2023-01-26 22:47:23 +00:00
func httpHandleFunc(urlPath string, filepath string, contentType string) {
2023-01-28 22:18:28 +00:00
urlPath = strings.ToLower(urlPath)
2023-01-28 21:32:20 +00:00
logger(readHttpYML() + "/" + urlPath + " <--> " + filepath + " <" + contentType + ">")
2023-01-26 22:47:23 +00:00
http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) {
2023-01-28 21:32:20 +00:00
logger(r.Method + " request -> " + readHttpYML() + "/" + urlPath + " <" + contentType + ">")
2023-01-28 21:28:31 +00:00
2023-01-26 22:47:23 +00:00
w.Header().Add("Content-Type", contentType)
2023-01-27 14:30:42 +00:00
io.WriteString(w, htmlReplacer(fileRead(filepath), urlPath))
2023-01-26 22:47:23 +00:00
})
}
func httpHandleFuncWithPOST(urlPath string, filepath string, contentType string) {
2023-01-28 21:32:20 +00:00
logger(readHttpYML() + "/" + urlPath + " <--> " + filepath + " <" + contentType + ">")
2023-01-26 22:47:23 +00:00
s := new(submit)
s.data = "null"
http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
2023-01-28 22:43:07 +00:00
r.ParseMultipartForm(10 << 20)
err := r.ParseForm()
errorPanic(err)
2023-01-28 22:09:31 +00:00
if filepath == "./web/pages/admin/dashboard.html" {
title := r.FormValue("title")
description := r.FormValue("description")
2023-01-28 22:43:07 +00:00
media, media_header, err := r.FormFile("media")
errorPanic(err)
2023-01-28 22:09:31 +00:00
date := r.FormValue("date")
2023-01-28 22:43:07 +00:00
if title != "" && description != "" && media != nil && date != "" {
2023-01-28 22:09:31 +00:00
logger("----------------POST----------------")
logger("title: " + title)
logger("descrtiption: " + description)
2023-01-28 22:43:07 +00:00
logger("media: " + media_header.Filename)
2023-01-28 22:09:31 +00:00
logger("date: " + date)
logger("----------------POST END----------------")
}
}
2023-01-26 22:47:23 +00:00
}
2023-01-28 21:32:20 +00:00
logger(r.Method + " request -> " + readHttpYML() + "/" + urlPath + " <" + contentType + ">")
2023-01-28 21:28:31 +00:00
2023-01-26 22:47:23 +00:00
w.Header().Add("Content-Type", contentType)
2023-01-27 14:30:42 +00:00
io.WriteString(w, htmlReplacer(fileRead(filepath), urlPath))
2023-01-26 22:47:23 +00:00
})
}