GoLang simple REST API should use GoRoutines

My question is very simple.

Should I use GoRoutines for a very simple REST API?

Basically, I make simple database queries, check sessions or make logins. Is any of these operations worth installing GoRoutine? When are GoRoutines useful and how do I set them up?

+7
rest go goroutine
source share
1 answer

The net/http package already takes care of this for you. As soon as you call Serve (or most likely ListenAndServe ), the following happens:

Serve accepts incoming HTTP connections in listener l, creating a new goroutine service for each. The goroutines services read requests and then call a handler to respond to them. The handler is usually zero, in which case DefaultServeMux is used.

See http://golang.org/pkg/net/http/ for more details.

You may want a different goroutine if the request necessitates a longer processing time and you do not want the client to wait.

+17
source share

All Articles