当前流行的Go web框架比较以及Gin介绍

当前流行的Go web框架比较以及Gin介绍,第1张

当前流行的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 with 🦍2021-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

Gin Web Framework

https://github.com/mingrammer/go-web-framework-stars

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/995212.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存