Created
June 3, 2013 15:21
-
-
Save johnboxall/5698940 to your computer and use it in GitHub Desktop.
Example of overriding `http.DefaultServeMux` of Go's HTTP server.
This file contains 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
// http://stackoverflow.com/questions/16888285/overriding-gos-default-http-sever-redirect-behaviour/16891953?noredirect=1#16891953 | |
package main | |
import ( | |
"fmt" | |
"net/http" | |
) | |
type Handler struct {} | |
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
uri := r.URL.Path | |
fmt.Fprint(w, uri) | |
return | |
} | |
func main() { | |
handler := new(Handler) | |
http.ListenAndServe(":8080", handler) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Empty struct is not needed, closure will do https://gist.github.com/tsenart/5fc18c659814c078378d