ctdo.de/http.go

32 lines
716 B
Go

package main
import (
"fmt"
"io"
"net/http"
)
func httpHandleFunc(urlPath string, filepath string, isMainpage bool, contentType string) {
if isMainpage {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", contentType)
io.WriteString(w, htmlReplacer(fileRead(filepath)))
})
} else {
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 {
fmt.Fprintf(w, "ParseForm() err: %v", err)
return
}
}
w.Header().Add("Content-Type", contentType)
io.WriteString(w, htmlReplacer(fileRead(filepath)))
})
}
}