http server with wrapper to non thread-safe library

115 views
Skip to first unread message

Jose

unread,
Oct 17, 2013, 1:28:02 PM10/17/13
to golan...@googlegroups.com
How can I use the Go http server to serve normal http requests and also wrap a non thread-safe library ?

My starting point is the example bradfitz posted on how to run the handlers serially:
https://groups.google.com/d/msg/golang-nuts/bTb_va88beA/0I58wwn8ekEJ

Ideally, I would also want to use the gorilla/mux library. Any ideas on how to "handle" this ?

thanks
jose

Jesse McNelis

unread,
Oct 17, 2013, 9:57:46 PM10/17/13
to Jose, golang-nuts
If you want to wrap a non thread-safe library the best option is to have a single goroutine responsible for it and have other goroutines submit requests over a channel.
Generally it's best for them to submit their request along with a channel for the reply.

You don't need to intentionally make the http requests process serially because all you need is serial access to the library which communicating with a single goroutine will provide.


--
=====================
http://jessta.id.au

Jose

unread,
Oct 20, 2013, 4:53:17 AM10/20/13
to Jesse McNelis, golang-nuts
thanks, I realize now it's simpler to do than I initially thought when looking at the example.
Reply all
Reply to author
Forward
0 new messages