以后风行的Go语言web框架

以下是截止到2021.10.03,GitHub上开源的Go Web框架状况。目前Gin是遥遥领先。

Project NameStarsForksOpen IssuesDescriptionLast Commit
gin518945889443Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.2021-09-30 02:04:28
beego27032531627beego is an open-source, high-performance web framework for the Go programming language.2021-09-18 15:08:26
kit21360219247A standard library for microservices.2021-09-28 15:01:29
echo20797184165High performance, minimalist Go web framework2021-09-26 15:56:43
fasthttp16135133646Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http2021-10-01 11:38:31
fiber1559078937⚡️ Express inspired web framework written in Go2021-10-02 01:54:34
mux15202141324A powerful HTTP router and URL matcher for building Go web servers with2021-09-14 12:12:19
kratos14913300135A Go framework for microservices.2021-09-30 06:31:25
httprouter13204127563A high performance HTTP request router that scales well2020-09-21 13:50:23
revel124001402103A high productivity, full-stack web framework for the Go language.2020-07-12 05:57:36
go-zero11533137234go-zero is a web and rpc framework written in Go. It's born to ensure the stability of the busy sites with resilient design. Builtin goctl greatly improves the development productivity.2021-10-02 10:16:59

Web框架须要做什么

咱们先思考下,一个残缺的Web开发框架须要做哪些事件

组件性能是否必须
server作为server,监听端口,承受申请
router路由和分组路由,能够把申请路由到对应的处理函数
middleware反对中间件,对外部发过来的http申请通过中间件解决,再给到对应的处理函数。例如http申请的日志记录、申请鉴权(比方校验token)、CORS反对、CSRF校验等。
template engine模板引擎,反对后端代码对html模板里的内容做渲染(render),返回给前端渲染好的html
ORM对象关系映射,能够把代码里的对象和关系数据库的表、字段做映射关联,通过操作对象来实现数据库的增删查改等操作。

Gin有什么

Gin的次要作者是Manu,Javier和Bo-Yi Wu,2016年公布第一个版本,目前是最受欢迎的开源Go框架。

Gin除了反对下面表格里列的server、router、middleware和template之外,还反对

  • Crash-free:解体复原,Gin能够捕获运行期解决http申请过程中的panic并且做recover操作,让服务始终可用。
  • JSON validation:JSON验证。Gin能够解析和验证request里的JSON内容,比方字段必填等。当然开发人员也能够抉择应用第三方的JSON validation工具,比方beego validation。
  • Error management:谬误治理。Gin提供了一种简略的形式能够收集http request处理过程中的谬误,最终中间件能够抉择把这些谬误写入到log文件、数据库或者发送到其它零碎。
  • Middleware Extendtable:能够自定义中间件。Gin除了自带的官网中间件之外,还反对用户自定义中间件,甚至能够把本人开发的中间件提交到官网代码仓库里。

Gin自身不反对ORM,如果想在Gin框架里应用ORM,能够抉择应用第三方的ORM,比方gorm。

文章开源

开源地址:https://github.com/jincheng9/go-tutorial

会有一个系列分享Go Web开发的方方面面。

欢送大家关注公众号:coding进阶,学习更多Go常识。


一起提高!

References

  • https://gin-gonic.com/
  • https://github.com/mingrammer...