From c7fd41469995d9bcf8fd90913a2f941ee5d7ab8e Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Sun, 16 Jul 2017 03:56:11 +1000 Subject: [PATCH] adding common handlers. --- server.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/server.go b/server.go index ae04502..a980df2 100644 --- a/server.go +++ b/server.go @@ -339,6 +339,16 @@ func getCrmFileID(urlPath string) string { return strings.TrimPrefix(urlPath, "/crmfiles/") } +func response400Handler(w http.ResponseWriter) { + w.WriteHeader(http.StatusBadRequest) + str, err := ioutil.ReadFile(GlobalPath.SinglePageEdit + "400.html") + if err == nil { + fmt.Fprintf(w, "%s", str) + return + } + fmt.Fprintf(w, "bad request") +} + func response404Handler(w http.ResponseWriter) { w.WriteHeader(http.StatusNotFound) str, err := ioutil.ReadFile(GlobalPath.SinglePageEdit + "404.html") @@ -349,6 +359,25 @@ func response404Handler(w http.ResponseWriter) { fmt.Fprintf(w, "not found") } +func response403Handler(w http.ResponseWriter) { + w.WriteHeader(http.StatusUnauthorized) + str, err := ioutil.ReadFile(GlobalPath.SinglePageEdit + "403.html") + if err == nil { + fmt.Fprintf(w, "%s", str) + return + } + fmt.Fprintf(w, "not authorized") +} + +func response500Handler(w http.ResponseWriter) { + w.WriteHeader(http.StatusInternalServerError) + str, err := ioutil.ReadFile(GlobalPath.SinglePageEdit + "500.html") + if err == nil { + fmt.Fprintf(w, "%s", str) + return + } + fmt.Fprintf(w, "server internal error") +} func getHTTPRequestQuery(r *http.Request, name string) (value string) { rq := r.URL.RawQuery m, _ := url.ParseQuery(rq)