문제

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