2023-01-26 20:58:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2023-01-26 22:13:44 +00:00
|
|
|
func httpHandleFunc(urlPath string, filepath string, isMainpage bool, contentType string) {
|
|
|
|
if isMainpage {
|
2023-01-26 20:58:13 +00:00
|
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
2023-01-26 22:13:44 +00:00
|
|
|
w.Header().Add("Content-Type", contentType)
|
|
|
|
io.WriteString(w, htmlReplacer(fileRead(filepath)))
|
2023-01-26 20:58:13 +00:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
s := new(submit)
|
|
|
|
s.data = "null"
|
2023-01-26 22:13:44 +00:00
|
|
|
http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) {
|
2023-01-26 20:58:13 +00:00
|
|
|
if r.Method == "POST" {
|
|
|
|
if err := r.ParseForm(); err != nil {
|
|
|
|
fmt.Fprintf(w, "ParseForm() err: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-26 22:13:44 +00:00
|
|
|
w.Header().Add("Content-Type", contentType)
|
2023-01-26 20:58:13 +00:00
|
|
|
|
2023-01-26 22:13:44 +00:00
|
|
|
io.WriteString(w, htmlReplacer(fileRead(filepath)))
|
2023-01-26 20:58:13 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|