ctdo.de/http.go

33 lines
733 B
Go
Raw Normal View History

package main
import (
"io"
"net/http"
)
2023-01-26 22:47:23 +00:00
func httpHandleFunc(urlPath string, filepath string, contentType string) {
s := new(submit)
s.data = "null"
http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", contentType)
io.WriteString(w, htmlReplacer(fileRead(filepath)))
})
}
func httpHandleFuncWithPOST(urlPath string, filepath string, contentType string) {
s := new(submit)
s.data = "null"
http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
if err := r.ParseForm(); err != nil {
panic(err)
}
2023-01-26 22:47:23 +00:00
}
2023-01-26 22:47:23 +00:00
w.Header().Add("Content-Type", contentType)
2023-01-26 22:47:23 +00:00
io.WriteString(w, htmlReplacer(fileRead(filepath)))
})
}