質問

My question is very simple.

Should I make use of GoRoutines for a very simple REST API?

I basically only do simple queries to a DB, verify sessions, or do logins. Is any of this operations worth setting up a GoRoutine? When are GoRoutines useful, and how should I set them up?

役に立ちましたか?

解決

The net/http package already takes care of this for you. Once you call Serve (or more likely ListenAndServe) the following happens:

Serve accepts incoming HTTP connections on the listener l, creating a new service goroutine for each. The service goroutines read requests and then call handler to reply to them. Handler is typically nil, in which case the DefaultServeMux is used.

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

You may want another goroutine if a request triggers the need for longer processing and you don't want to make the client wait.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top