Skip to content

Instantly share code, notes, and snippets.

@kevburnsjr
Last active July 6, 2017 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevburnsjr/39d7233ec21989c4bb2b50ad95f6788b to your computer and use it in GitHub Desktop.
Save kevburnsjr/39d7233ec21989c4bb2b50ad95f6788b to your computer and use it in GitHub Desktop.
import (
"./controller"
"net/http"
)
var routes = map[string]func(http.ResponseWriter, *http.Request){
"/": controller.Index,
"/acct": controller.Acct,
"/acct/auth": controller.AcctAuth,
// etc...
}
func ServeHttp(w http.ResponseWriter, r *http.Request) {
if handler, ok := routes[r.URL.Path]; ok {
handler(w, r)
} else {
http.Error(w, "Not Found : "+r.URL.Path, 404)
return
}
}
func main() {
http.ListenAndServe(":80", http.HandlerFunc(ServeHttp))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment