Created
September 19, 2019 21:25
-
-
Save webdevwilson/5f3531857adb28b91936c34eacae891c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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