2023-01-26 20:58:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2023-01-26 22:47:23 +00:00
|
|
|
func httpHandleFunc(urlPath string, filepath string, contentType string) {
|
2023-01-28 20:58:08 +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) {
|
|
|
|
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 20:58:08 +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 20:43:07 +00:00
|
|
|
err := r.ParseForm()
|
|
|
|
errorPanic(err)
|
2023-01-26 22:47:23 +00:00
|
|
|
}
|
2023-01-26 20:58:13 +00:00
|
|
|
|
2023-01-26 22:47:23 +00:00
|
|
|
w.Header().Add("Content-Type", contentType)
|
2023-01-26 20:58:13 +00:00
|
|
|
|
2023-01-27 14:30:42 +00:00
|
|
|
io.WriteString(w, htmlReplacer(fileRead(filepath), urlPath))
|
2023-01-26 22:47:23 +00:00
|
|
|
})
|
2023-01-26 20:58:13 +00:00
|
|
|
}
|