Re: [go-nuts] Rate controlling the Go http server

2018-02-02 Thread mrx
Thanks again, much appreciated! Patrik Iselind Den 2 feb. 2018 16:33 skrev "Henrik Johansson" : > Happy to help! > > The limit can be anything from the link above or something more advanced > that Jesper suggested. The skeleton could be as outlined above however. > > On

Re: [go-nuts] Rate controlling the Go http server

2018-02-02 Thread Henrik Johansson
Happy to help! The limit can be anything from the link above or something more advanced that Jesper suggested. The skeleton could be as outlined above however. On Fri, Feb 2, 2018, 15:40 mrx wrote: > On Fri, Feb 2, 2018 at 1:28 PM, Henrik Johansson

Re: [go-nuts] Rate controlling the Go http server

2018-02-02 Thread mrx
On Fri, Feb 2, 2018 at 1:28 PM, Henrik Johansson wrote: > You can either use one of the existing other routers that have meddleware > support or you could wrap your handlers in another handler much like this: > > handle("/foo",wrapHandler(rateLimiter, realHandler)) > > func

Re: [go-nuts] Rate controlling the Go http server

2018-02-02 Thread Henrik Johansson
You can either use one of the existing other routers that have meddleware support or you could wrap your handlers in another handler much like this: handle("/foo",wrapHandler(rateLimiter, realHandler)) func wrapHandler(limit *ARateLimiter, handler func(http.ResponseWriter, *http.Request))

Re: [go-nuts] Rate controlling the Go http server

2018-02-02 Thread Patrik Iselind
Den fredag 2 februari 2018 kl. 11:50:43 UTC+1 skrev Jesper Louis Andersen: > > A simple solution is to have a channel of type struct{} of some bound, say > 10. A process only gives service as long as it can pull a message from the > channel. > How would i hook in such a channel in the http

Re: [go-nuts] Rate controlling the Go http server

2018-02-02 Thread Patrik Iselind
Den fredag 2 februari 2018 kl. 11:50:22 UTC+1 skrev Henrik Johansson: > > I guess a middleware wrapping any of the available rate limiters > https://godoc.org/?q=rate+limit should do the trick? > Thanks a lot for your suggestion. How do i add middleware to the HTTP server in the first place? I

[go-nuts] Rate controlling the Go http server

2018-02-02 Thread Patrik Iselind
Hi, If i define a webserver as such (taken from the docs) http.Handle("/foo", fooHandler) http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) }) log.Fatal(http.ListenAndServe(":8080", nil)) How do i control

Re: [go-nuts] Rate controlling the Go http server

2018-02-02 Thread Henrik Johansson
I guess a middleware wrapping any of the available rate limiters https://godoc.org/?q=rate+limit should do the trick? fre 2 feb. 2018 kl 11:30 skrev Patrik Iselind : > Hi, > > If i define a webserver as such (taken from the docs) > > http.Handle("/foo", fooHandler) > >