0.必备功能
坑多了,自然想多要一些糖,这样一个理想的RESTful框架,至少需要以下功能
- RAML支持
- CORS支持
- JSON支持
- 良好的Router机制
- 简单的Controller、Service分离
ORM支持(最好带migrate)
0.1 中间件大搜集
RestGate
支持框架:Negroni,Martini,Gin 为REST API提供endpoints的安全验证机制
1.0 gin
w 279 s 4087 f 395 https://gin-gonic.github.io/gin https://github.com/gin-gonic/gin
REST最佳实践 https://medium.com/@etiennerouzeaud/how-to-create-a-basic-restful-api-in-go-c8e032ba3181
- 评分 9⁄10
- api编写简洁
x20-x45 fastest than Martini
1.1 go-json-rest
w 98 s 1816 fork 176
https://github.com/ant0ine/go-json-rest
- 评分 7⁄10
- Fast & scalable URL routing
- Test package to help writing tests
- routing engine 支持正则
- 检测统计by Memcached
GORM 支持 migrate
Middlewares like
Logging
Gzip
CORS
Auth
Status
AccessLogApache
AccessLogJson
AuthBasic
ContentTypeChecker
If
JsonIndent
Jsonp
PoweredBy
Recorder
Timer
Statsd
JWT
AuthToken
SecureRedirect
go get github.com/ant0ine/go-json-rest/rest
1.2 Echo
w 140 s 2326 f 143 https://github.com/labstack/echo faster than gin,martini,Negroni
1.3 go-relax
w 8 s 105 f 2
https://github.com/codehack/go-relax
- 评分 5⁄10
- 遵循ROA原则
- HATEOAS支持
- default json, also XML
routing engine 支持正则
支持的中间件
Content
CORS
GZip
Logging
Method override
Security
Limits
1.4 go-rest
评分 3⁄10
Small only three functions: HandleGET, HandlePOST, RunServer
Evil anti-pattern
ZZ.自主开发
作者:ryanemax
微信关注:ryanemax (刘雨飏)
本文出处:https://romantic-hoover-f991f1.netlify.com/cookbook/api/golangforrest/
授权协议:
CC BY-SA 4.0