33 lines
751 B
Go
33 lines
751 B
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
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), urlPath))
|
|
})
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
w.Header().Add("Content-Type", contentType)
|
|
|
|
io.WriteString(w, htmlReplacer(fileRead(filepath), urlPath))
|
|
})
|
|
}
|