Skip to content

Repository files navigation

简介

Gaea Logo

Gaea是一基于Gin的Web框架。 在实际工作中,在将项目应用于生产环境之前,还需要解决一系列其他工程问题, 否则,系统的可移植性将很差,并且开发人员将无法专注于业务开发。 集成到一套完整的解决方案中:依赖关系管理,配置管理,编译和部署,监视和警报,并支持一键式快速构建Web应用程序。 如果您正在考虑用Golang编写Web服务器,那么Gaea无疑是您的最佳选择!

Document

Documentation

中文文档

安装

安装脚手架

通过 rigger脚手架可一键创建Gaea模板的api项目

生成框架

此处以"myproject"为项目名称

$ rigger new api myproject
正克隆到 '/winshare/go/src/myproject'...
myprojec项目已创建完成, 使用:
cd /winshare/go/src/myproject && rigger build 

编译

//Will use makefile to compile and generate binary files to the bin directory
$ cdgaea
$ make

help

$ ./bin/myproject--helpUsageof ./bin/myproject:
-cstring指定ini配置文件以程序的二进制文件(myproject)为相对目录正确的相对目录加载方式-c ../conf/conf_xxx.ini默认为加载 ../conf/conf.ini-pstring配置文件的前缀设置用于以绝对路径形式加载-cconf.ini-p/usr/pathto/myproject/conf-cfgstringjsonconfigpath (default"conf/config.json") -extendedstring扩展参数程序未定义使用用途用户可自行处理-fforeground-mmock开关-sstringstartorstop-usr1stringuserdefinedflag-usr1-usr2stringuserdefinedflag-usr2-usr3stringuserdefinedflag-usr3-usr4stringuserdefinedflag-usr4-usr5stringuserdefinedflag-usr5-vversion

Example

1.Config server port

//conf/conf.ini
[Server]
;Gin启动的模式,可选debug/releasemode=debug
;httpserver监听端口addr=:9898
;是否开启平滑重启grace=truereadTimeout=3swriteTimeout=3s
;...

2.Add router

//app/router/router.go is the file that manage all URIfuncRegisterRouter(router*gin.Engine) {
entry:=router.Group("/demo", middleware.PerfMiddleware(), middleware.XesLoggerMiddleware())
entry.GET("/test", democontroller.GaeaDemo)
}

4.Controller (mvc programming style)

//app/router/funcGaeaDemo(ctx*gin.Context) {
goCtx:=xesgin.TransferToContext(ctx)
param:=ctx.PostForm("param")
ret, err:=demoservice.DoFun(goCtx, param)
iferr!=nil {
resp:=xesgin.Error(err)
ctx.JSON(http.StatusOK, resp)
} else {
resp:=xesgin.Success(ret)
ctx.JSON(http.StatusOK, resp)
}
}

运行

$ riggerstart2019/11/0621:50:03CONFINIT,path:../conf/conf.ini
[GIN-debug] [WARNING] Runningin"debug" mode. Switchto"release"modeinproduction.
-usingenv: exportGIN_MODE=release-using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET/demo/test-->myproject/app/controller/democontroller.MyXesGoDemo (3handlers)
2019/11/0621:50:03 [overseermaster] run2019/11/0621:50:04 [overseermaster] starting/winshare/go/src/myproject/bin/myproject2019/11/0621:50:04CONFINIT,path:../conf/conf.ini
[GIN-debug] [WARNING] Runningin"debug" mode. Switchto"release"modeinproduction.
-usingenv: exportGIN_MODE=release-usingcode: gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET/demo/test-->myproject/app/controller/democontroller.MyXesGoDemo (3handlers)
2019/11/0621:50:04 [overseerslave#1] run2019/11/0621:50:04 [overseerslave#1] startprogram

测试

$ curlhttp://127.0.0.1:9898/demo/test
{"code":0,"data":{"ret1":"Welcometousemyproject!"},"msg":"ok","stat":1}

至此,我们已经通过Gaea搭建了一个web服务! 接下来我们进一步学习Gaea 相关配置、特性、组件应用等主题

各大主流框架路由性能对比

Gaea Logo

(图片来自于网络)

Gaea性能压测

Gaea框架相比于原生Gin 影响性能的点其实是全部集中在中间件上,因为每次http请求都会跑一边,所以,观测下在各个中间开启时对整体性能的影响情况

压测条件

条件
系统virtualbox 虚拟机上 centos7
内存1GB
CPU单核
请求数量10万
并发数量100
传输数据{"code":0,"data":"hell world","msg":"ok","stat":1}

压测结果

Gaea Logo

从图中我们可以明显看出:

  • Gaea的默认配置会带来一定的性能耗损,大约30%
  • 其中Logger中间件在各个中间件影响性能比重最大,其它中间件几乎可以忽略不计

在实际项目应用中,当Logger 中间件是瓶颈点时,我们可以关闭它,毕竟请求日志在网关层也会记录!

此外,对日志库使用建议日志级别设定为WARNING

联系我们

Contact Us

(微信扫一扫,申请加入开发讨论微信群)

Releases

Packages

Contributors

Languages