Skip to content

a go app skeleton by revel, add swagger-ui, go-swagger

Notifications You must be signed in to change notification settings

inhere/go-revel-skeleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

application

go 框架 revel 配合 swagger-ui 应用骨架搭建介绍

相关项目

  • revel 一个全栈式 golang 框架
  • go-swagger 通过注释生成 swagger.json
  • swagger-ui 显示API文档。 将 swagger.json 渲染成 html

revel

安装revel

go get -u -v github.com/revel/cmd/revel
revel -h

创建项目

cd $GOPATH/src
revel new {PROJECT_NAME}
ll {PROJECT_NAME}

运行项目

转到项目目录下执行 revel run 访问 http://localhost:9000/

go-swagger

用于生成 swagger-ui 可读的json 文档文件

安装

go get -u -v github.com/go-swagger/go-swagger/cmd/swagger
swagger -h

文档生成

在项目目录执行

swagger generate spec -o swagger-ui/docs/swagger.json
swagger generate spec -i ./swagger.yml -o swagger-ui/docs/swagger.json

因为 revel 的 main.go 是自动生成到 app/tmp 的,所以需要到 main.go 所在目录运行上述命令才行

cd app/tmp
swagger generate spec -o ../../swagger-ui/docs/swagger.json

swagger-ui

swagger-ui 下载 npm install swagger-ui-dist。或者到 github 下载

拷贝 dist 下的所有文件到项目目录下 swagger-ui 目录

文档查看

  • 配置静态资源访问

路由配置 conf/routes

# For swagger UI
GET    /swagger-ui/*filepath                   Static.Serve("swagger-ui")
GET    /swagger-ui/                            Static.Serve("swagger-ui","index.html")
  • 访问: 127.0.0.1:9000/swagger-ui/

Releases

No releases published

Packages

No packages published