package main import ( "io" "net/http" "strings" ) func httpHandleFunc(urlPath string, filepath string, contentType string) { urlPath = strings.ToLower(urlPath) logger(readHttpYML() + "/" + urlPath + " <--> " + filepath + " <" + contentType + ">") http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) { logger(r.Method + " request -> " + readHttpYML() + "/" + urlPath + " <" + contentType + ">") w.Header().Add("Content-Type", contentType) io.WriteString(w, htmlReplacer(fileRead(filepath), urlPath)) }) } func httpHandleFuncWithPOST(urlPath string, filepath string, contentType string) { logger(readHttpYML() + "/" + urlPath + " <--> " + filepath + " <" + contentType + ">") s := new(submit) s.data = "null" http.HandleFunc("/"+urlPath, func(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { r.ParseMultipartForm(10 << 20) err := r.ParseForm() errorPanic(err) if filepath == "./web/pages/admin/dashboard.html" { title := r.FormValue("title") description := r.FormValue("description") media, media_header, err := r.FormFile("media") errorPanic(err) date := r.FormValue("date") if title != "" && description != "" && media != nil && date != "" { logger("----------------POST----------------") logger("title: " + title) logger("descrtiption: " + description) logger("media: " + media_header.Filename) logger("date: " + date) logger("----------------POST END----------------") } } } logger(r.Method + " request -> " + readHttpYML() + "/" + urlPath + " <" + contentType + ">") w.Header().Add("Content-Type", contentType) io.WriteString(w, htmlReplacer(fileRead(filepath), urlPath)) }) }