Explorar el Código

adding common handlers.

master
Patrick Peng Sun hace 8 años
padre
commit
c7fd414699
Se han modificado 1 ficheros con 29 adiciones y 0 borrados
  1. +29
    -0
      server.go

+ 29
- 0
server.go Ver fichero

return strings.TrimPrefix(urlPath, "/crmfiles/") 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) { func response404Handler(w http.ResponseWriter) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
str, err := ioutil.ReadFile(GlobalPath.SinglePageEdit + "404.html") str, err := ioutil.ReadFile(GlobalPath.SinglePageEdit + "404.html")
fmt.Fprintf(w, "not found") 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) { func getHTTPRequestQuery(r *http.Request, name string) (value string) {
rq := r.URL.RawQuery rq := r.URL.RawQuery
m, _ := url.ParseQuery(rq) m, _ := url.ParseQuery(rq)

Cargando…
Cancelar
Guardar