[Turn] six of the best Go language Web framework

link:https://www.cnblogs.com/desmond123/p/9821687.html

If you design a small application for yourself, you may not need a Web framework, but if you are doing the production, then you definitely need a, a good application.

While you think you have the necessary knowledge and experience, but if you are willing to write all the code for these functions on their own?
Do you have time to find production-level external package to get the job done? Are you sure this will apply to the rest of your keeping it?

These are the reasons that we use to promote the framework, if other people have done these tedious and hard work, we do not want to write your own all the necessary functions.

Introduction

Go is a fast-growing open-source programming language, designed to build a simple, fast, reliable software. See what great companies use Go to support their services.

This article provides all the necessary information to help developers learn more about developing Web applications using Go of the best options.

This article contains the most detailed comparative framework, from as many angles by comparing the best known Web Framework: popularity, support and built-in features:

Beego: open source, high-performance Web framework Go programming language.

Buffalo: Rapid Web Development w / Go.

Echo: high performance, minimalist Go Web framework.

Gin: HTTP Web framework with Go (Golang) written. It has a similar Martini's API, with better performance.

Iris: Go in the Universe fastest Web framework. MVC fully functional. Today embrace the future.

Revel: Go high productivity language, full-stack Web framework.

prestige

Sort by popularity (star)

Frame names current version Watch Stars Forks Issues Open Issues Close Frame birthday Last Updated Author
TPU stable v1.10.0 1159 16762 3557 544 1667 2012 July 31, 2018 GMT + 8 9:18 pm @astaxie
buffalo stable 0.12.6 125 3317 259 51 508 2014 August 15, 2018 GMT + 8 5:26 am @markbates
Echo stable 3.1 513 11474 1010 108 665 2015 August 29, 2018 GMT + 8 11:49 AM @Visr
Gin stable v1.stable 915 20122 2377 126 805 2014 September 1, 2018 GMT + 8 4:38 am @manucorporat
Iris stable v11 569 11604 1177 10 888 2016 September 2, 2018 GMT + 8 12:27 AM @kataras
Revel stable 0.19.0 546 10208 1260 63 769 2011 July 13, 2018 GMT + 8 3:43 am @robfig

learning curve

Frame names Examples Referring to the example Live Support
TPU 49 https://beego.me/docs  
buffalo 6 https://gobuffalo.io/docs/installation slack
Echo 20 https://echo.labstack.com/cookbook/hello-world  
Gin 15 https://github.com/gin-gonic/gin/tree/master/examples grid
Iris 92 https://github.com/kataras/iris/tree/master/_examples rocket cat
Revel 6 http://revel.github.io/examples/index.html grid

Here astaxie and kataras very good, other frameworks there will be more examples, at least for me, if I switch to a new framework, which is the most quickly grasp as much information as most of local resources. An example of just 1000 words.

Core functions

Sort Up, fewer features

Core Function Name Iris TPU Revel Echo Gin Buffalo
Router: name and path parameters wildcards (Router: Named Path Parameters & Wildcard *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Router: Regular Expressions (Router: Regex *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Router: packet (Router: Grouping *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Router: All of the above mixed conflict-free (Router: All the above Mixed Without Conflict *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Router: Custom HTTPError (Router: Custom HTTP Errors *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
And net/httpis compatible with 100% (100% compatible with net / http *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Middleware ecosystem (Middleware ecosystem *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Sinatra风格 API (Sinatra-like API *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Server: Automatic HTTPS(Server: Automatic HTTPS *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Server: normal shutdown (Server: Gracefully Shutdown *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Server: Multi-monitor (Server: Multi Listeners *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Complete HTTP/2(Full HTTP / 2 *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Standard (standard) Standard (standard)
Subdomain (Subdomains *) Go Web Iris Chinese network Secondary (Secondary) Secondary (Secondary) Secondary (Secondary) Secondary (Secondary) Secondary (Secondary)
Session Management (Sessions *) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Secondary (Secondary)
Websockets Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
嵌入到应用(View (aka Templates) Embedded Into App*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
View视图引擎 STD(View Engine: STD*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
View视图引擎 Pug(View Engine: Pug*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
View视图引擎 Django(View Engine: Django*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
View视图引擎 Handlebars(View Engine: Handlebars*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
View视图引擎 Amber(View Engine: Amber*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
数据渲染器:Markdown,JSON,JSONP,XML Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
MVC Go Web Iris Chinese network Go Web Iris Chinese network generator Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
缓存(Caching*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
文件服务器(File Server*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
文件服务器:嵌入到应用程序(File Server: Embedded Into App*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
响应可以在发送之前的生命周期中多次修改(Response can be Modified Many times through lifecycle before sent*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Gzip Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network (中间件) middleware (中间件)middleware (中间件) middleware
测试框架(Testing Framework*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
Typescript Transpiler Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
在线编辑(Online Editor*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
日志系统(Logging System*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
维护和自动更新(Maintenance & Auto-Updates*) Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network Go Web Iris Chinese network
性能(Performance) ★★★★★ ★★★ ★★ ★★★★★ ★★★★★ ★★★

Go中最着名的“Web框架”并不是真正的框架,这意味着:Echo,Gin和Buffalo并不是真正的(功能齐全的)Web框架但Go社区的大多数人都认为他们是。因此他们认为它们与Iris,Beego或Revel相当,因此,我们也有义务将它们纳入此清单。
除了 Beego 和 Revel 之外,所有上述框架都可以适应任何中间件这是为 net/http 创建的,其中一些可以轻松地和其他人一起完成有一些黑客[甚至痛苦是这里的选择]。

词汇

路由:命名路径参数和通配符(Router: Named Path Parameters & Wildcard)

当您可以将处理程序注册到具有动态路径的路由时。

示例命名路径参数:

"/user/{username}" 匹配 "/user/me", "/user/speedwheel" etc

路径参数username匹配值分别是 me 和 speedwheel

示例通配符:

"/user/{path *wildcard}" matches to "/user/some/path/here", "/user/this/is/a/dynamic/multi/level/path" etc

path 路径参数的值分别是some/path/herethis/is/a/dynamic/multi/level/path

Iris也支持一种称为宏的功能,可以描述为/user/{username:string}或/user/{username:int min(1)}。

路由:正则表达式(Router: Regex)

当您可以使用带有过滤器的动态路径向具有过滤器的路径注册处理程序时,应该传递一些处理程序以执行处理程序。

示例:

"/user/{id ^[0-9]$}" matches to "/user/42" but not to "/user/somestring"

id路径参数的值为42。

路由:分组(Router: Grouping)

当您可以将公共逻辑或中间件/处理程序注册到共享相同路径前缀的特定路由组时。

示例:

myGroup := Group("/user", userAuthenticationMiddleware) myGroup.Handle("GET", "/", userHandler) myGroup.Handle("GET", "/profile", userProfileHandler) myGroup.Handle("GET", "/signup", getUserSignupForm)
  • /user
  • /user/profile
  • /user/signup

您甚至可以从组中创建子组:

myGroup.Group("/messages", optionalUserMessagesMiddleware) myGroup.Handle("GET', "/{id}", getMessageByID)
  • /user/messages/{id}

路由:以上所有混合无冲突(Router: All the above Mixed Without Conflict)

这是一个先进但有用的功能,我们许多人希望它由路由器或Web框架支持,目前只有Iris在Go世界中支持这一功能。

这意味着/{path *wildcard}/user/{username}/user/static/user/{path*wildcard}之类的东西可以在同一个路由器中注册,它可以正确匹配而不会受到静态路径的冲突(/user/static)或通配符(/{path*wildcard})。

路由:自定义HTTP错误(Router: Custom HTTP Errors)

当您可以为“错误”状态代码注册处理程序时。 错误http状态代码是> = 400状态代码,i.s Not Found 404

示例:

OnErrorCode(404, myNotFoundHandler)

上面的大多数Web框架仅支持404,405和500注册,但像Iris,Beego和Revel这样的功能完全支持任何状态代码甚至任何错误代码(Iris仅支持任何错误)。

100% compatible with net/http (与net/http 100%兼容)

意味着你有:

  • 框架为您提供了直接访问*http.Requesthttp.ResponseWriter的上下文。
  • 一种将net/http处理程序转换为特定框架的Handler类型的方法。

中间件生态系统 (Middleware ecosystem)

当您不必自己用中间件包装每个处理程序时,框架会为您提供一个完整的引擎来定义流,全局或每个路由或每组路由。 i.e Use(middleware), Done(middleware) etc.

类似 Sinatra API (Sinatra-like API)

类似于SinatraAPIRegister在运行时处理程序中用于特定HTTP方法(和路径参数)的路由。

示例:

.Get or GET("/path", gethandler) .Post or POST("/path", postHandler) .Put or PUT("/path", putHandler) and etc.

服务器:自动HTTPS(Server: Automatic HTTPS)

当框架的服务器支持注册和自动续订SSL认证以管理SSL/TLS传入连接(https)时。 最着名的自动https提供程序是letsencrypt

服务器:正常关机 (Server: Gracefully Shutdown)

按CTRL + C关闭终端应用程序时; 服务器将正常关闭,等待一些连接完成其工作(具有特定的超时)或触发自定义事件以进行清理(即数据库关闭)。

服务器:多监听(Server: Multi Listeners)

当框架的服务器支持注册自定义net.Listener或使用多个http服务器和地址提供Web应用程序时。

完整的HTTP/2(Full HTTP/2)

当框架支持带有httpsHTTP/2和服务器推送功能时。

子域(Subdomains)

当您可以直接从Web应用程序注册每个x,y子域的路由。

这个框架不支持这个功能,但你仍然可以通过启动多个http服务器来实现它,这样做的缺点是主应用程序和子域没有连接,默认情况下不可能在它们之间共享逻辑。

会话(Sessions)

  • 支持http会话并准备在特定处理程序中使用时。
  • 一些Web框架支持后端数据库来存储会话,因此您可以在服务器重新启动之间获得持久性。Buffalo使用gorilla会话,这些会话比其他实现慢一点。

示例:

func setValue(context http_context){ s := Sessions.New(http_context) s.Set("key", "my value") } func getValue(context http_context){ s := Sessions.New(http_context) myValue := s.Get("key") } func logoutHandler(context http_context){ Sessions.Destroy(http_context) }

Wiki: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#HTTP_session

套接字(WebSockets)

当框架支持websocket通信协议时。 实现是不同的。

您应该搜索他们的示例以查看适合您的内容。 我尝试所有这些的同事告诉我,与其他API相比,Iris使用更简单的API实现了最具特色的webosocket连接。

Wiki: https://en.wikipedia.org/wiki/WebSocket

视图(aka模板)嵌入到应用程序中

通常,您必须将所有模板文件与Web应用程序的可执行文件并行传输。 嵌入到应用程序意味着框架支持与go-bindata集成,因此最终的可执行文件包含其中的模板,表示为[]byte

什么是视图引擎?

当框架支持模板加载,自定义和构建模板功能时,可以在关键部件上完成。

视图引擎:STD

当框架支持通过标准html/template解析器加载模板时。

视图引擎:Pug

当框架支持通过Pug解析器加载模板时。

视图引擎:Django

当框架支持通过Django解析器加载模板时。

视图引擎:Handlebars

当框架支持通过Handlebars解析器加载模板时。

视图引擎:Amber

当框架支持通过Amber解析器加载模板时。

渲染:Markdown,JSON,JSONP,XML(Renderer: Markdown, JSON, JSONP, XML)

当框架的上下文为您提供一种简单的方法来轻松地发送/和自定义各种内容类型的响应。

MVC

模型 - 视图 - 控制器(MVC)是用于在计算机上实现用户界面的软件架构模式。
它将给定的应用程序划分为三个相互关联的部分。
这样做是为了将信息的内部表示与向用户呈现和接受信息的方式分开。
MVC设计模式将这些主要组件分离,从而实现高效的代码重用和并行开发。

  • Iris支持完整的MVC功能,可以在运行时注册。
  • Beego仅支持方法和模型匹配,可以在运行时注册。
  • Revel支持方法,路径和模型匹配,只能通过生成器(必须运行以构建Web应用程序的不同软件)注册。

Wiki: https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

高速缓存(Caching)

Web缓存(或HTTP缓存)是用于临时存储(缓存)Web文档(例如HTML页面和图像)的信息技术,以减少服务器滞后。
通过它的Web缓存系统文档; 如果满足某些条件,可以满足后续要求。[1] Web缓存系统可以指设备或计算机程序。

Wiki: https://en.wikipedia.org/wiki/Web_cache

文件服务器(File Server)

当您可以将(物理)目录注册到将自动向客户端提供此目录文件的路由时。

文件服务器:嵌入到应用程序(File Server: Embedded Into App)

通常,您必须传输所有静态文件(如资产; css,javascript文件…)以及应用程序的可执行文件。
支持此功能的框架使您有机会将所有这些数据嵌入到应用程序中,表示为[]byte,它们的响应时间也更快,因为服务器可以直接为它们提供服务,而无需在物理位置查找文件。

响应可以在发送之前的生命周期中多次修改(Response can be Modified Many times through lifecycle before sent)

目前只有Iris通过其http_context中的内置响应编写器支持此功能。

当框架支持此功能时,您可以在发送到客户端之前检索或重置或修改写入的状态代码,正文和标题(在基于net/http的Web框架中,默认情况下这是不可能的,因为无法检索或更改正文和状态代码 书面)。

Gzip

当你在路由的处理程序中并且你可以更改响应编写器以便使用gzip压缩发送响应时,框架应该处理已发送的头文件,如果发生任何错误,它应该将响应写入恢复正常。
它也应该能够检查客户端是否支持gzip。

gzip是一种文件格式和用于文件压缩和解压缩的软件应用程序

Wiki: https://en.wikipedia.org/wiki/Gzip

测试框架(Testing Framework)

当您可以使用特定的框架库测试HTTP时,它的工作就是帮助您轻松编写更好的测试。

示例(目前,只有Iris支持):

func TestAPI(t *testing.T) { app := myIrisApp() tt := httptest.New(t, app) tt.GET("/admin").WithBasicAuth("name", "pass").Expect(). Status(httptest.StatusOK).Body().Equal("welcome") }

myIrisApp返回你想象中的Web应用程序,它有一个/admin的GET处理程序,受基本身份验证保护。

上面的简单测试检查/admin是否以状态OK响应,并且使用特定用户名和密码传递身份验证,并且其正文为welcome

Typescript Transpiler

TypescriptThe goal is a superset of the ES6, in addition to all the standard definition of new things, we will also add a static type system.
TypescriptThere is also a converter, it will be our Typescriptcodes (ie ES6 + type) or ES3 ES5 converted to  javascriptcode, so we can use it in today's browsers.

Online editing (Online Editor)

With online editor online editor, you can quickly and easily compile and run the code online.

Logging system (Logging System)

Custom logging system by providing a coding such as color, format, separating the log level, different logging other useful functions to extend the rear end of the unit package behavior log.

Maintenance and automatic update (Maintenance & Auto-Updates)

A non-invasive way to inform users "instant" update framework.

 

 

Extended Information

1. The best 6 Go language Web framework

Guess you like

Origin www.cnblogs.com/fanbi/p/12101406.html