On Monday, 19 June 2017 01:02:37 UTC+3, Axel Wagner wrote:
>
> Hey gophers,
>
> in an attempt to rein in the HTTP router epidemic, I tried writing down a) 
> why I think *any* router/muxer might not be a good thing to use (much 
> less write) and b) what I consider good, practical advice on how to route 
> requests instead. It's not rocket science or especially novel, but I wanted 
> to provide more useful advice than just saying "just use net/http" and 
> haven't seen that a lot previously.
>
> Feedback is welcome :)
> http://blog.merovius.de/2017/06/18/how-not-to-use-an-http-router.html
>

I've also used this approach for very simple endpoints:

func ServeHTTP(w http.ResponseWriter, r *http.Request) {
type rr struct{ method, path string } // rr = "resource request"
switch (rr{r.Method, r.URL.Path}) {
default:
http.Error(w, "Invalid request.", http.StatusBadRequest)
retun
case rr{http.MethodGet, "/"}:
// handle index
case rr{http.MethodGet, "/favicon.ico"}:
// serve icon
case rr{http.MethodGet, "/list"}:
// serve list
case rr{http.MethodPost, "/save"}:
// ..
}
}

Of course this can be combined with getting the ShiftPath and other things, 
when necessary.

+ Egon

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to