Skip to content

Instantly share code, notes, and snippets.

@webdevwilson
Created September 19, 2019 21:25
Show Gist options
  • Select an option

  • Save webdevwilson/5f3531857adb28b91936c34eacae891c to your computer and use it in GitHub Desktop.

Select an option

Save webdevwilson/5f3531857adb28b91936c34eacae891c to your computer and use it in GitHub Desktop.
func (h *httpHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// strip the path prefix
uri := req.URL.Path[len(h.pathPrefix):]
var data interface{}
var err error
if uri == "/" {
http.Redirect(w, req, fmt.Sprintf("%s/hello", h.pathPrefix), 302)
return
} else if uri == "/hello" {
data, err = controller.SayHello()
} else {
w.WriteHeader(http.StatusNotFound)
return
}
if err != nil {
internalError(w, req, err)
return
}
success(w, req, data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment