Skip to content

Instantly share code, notes, and snippets.

@johnboxall
Created June 3, 2013 15:21
Show Gist options
  • Save johnboxall/5698940 to your computer and use it in GitHub Desktop.
Save johnboxall/5698940 to your computer and use it in GitHub Desktop.
Example of overriding `http.DefaultServeMux` of Go's HTTP server.
// 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)
}
@sslavic
Copy link

sslavic commented Feb 12, 2018

Empty struct is not needed, closure will do https://gist.github.com/tsenart/5fc18c659814c078378d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment