dongtao9158 2014-03-07 10:38
浏览 40
已采纳

GoLang简单的REST API应该使用GoRoutines

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?

  • 写回答

1条回答 默认 最新

  • dongpang1232 2014-03-07 11:09
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料