Golang Gin 项目使用 Swagger
Golang Gin 项目使用 Swagger
标签(空格分隔): Go
首先需要github.com/swaggo/gin-swagger
和github.com/swaggo/gin-swagger/swaggerFiles
(参见gin-swagger)。
然后根据 github.com/swaggo/swag/cmd/swag文档获取到swag工具;执行swag init
在项目根目录下生成docs
文件夹。然后在路由中import _ "/docs"
。这时候编译程序,打开http://localhost:8080/swagger/index.html
就可以看到API。有时候打开页面js报错,多刷新几次就有了(原因未知)。
注意项目目录下,包依赖不能用src等名称,请看以下源码:
//exclude vendor folder
if ext := filepath.Ext(path); ext == ".go" &&
!strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+"vendor"+string(os.PathSeparator)) &&
!strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+".history"+string(os.PathSeparator)) &&
!strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+".idea"+string(os.PathSeparator)) &&
!strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+".git"+string(os.PathSeparator)) {
fset := token.NewFileSet() // positions are relative to fset
astFile, err := goparser.ParseFile(fset, path, nil, goparser.ParseComments)
swag工具排除了vendor
、.history
、.idea
、.git
目录下的文件(参见pl)。可以使用godep等工具将依赖包放在vendor目录下。
Golang Gin 项目使用 Swagger的更多相关文章
- Golang Gin 项目包依赖管理 godep 使用
Golang Gin 项目包依赖管理 godep 使用 标签(空格分隔): Go 在按照github.com/tools/godep文档go get完包以后,调整项目结构为$GOPATH/src/$P ...
- golang gin框架 集成swagger 自动生成文档
goswagger github仓库 https://github.com/swaggo/swag 安装 swag cli 1.因为网络原因,先安装gopm 管理工具 go get -v -u git ...
- golang gin框架 使用swagger生成api文档
github地址:https://github.com/swaggo/gin-swagger 1.下载swag $ go get -u github.com/swaggo/swag/cmd/swag ...
- Golang优秀开源项目汇总, 10大流行Go语言开源项目, golang 开源项目全集(golang/go/wiki/Projects), GitHub上优秀的Go开源项目
Golang优秀开源项目汇总(持续更新...)我把这个汇总放在github上了, 后面更新也会在github上更新. https://github.com/hackstoic/golang-open- ...
- Golang Gin实践 番外 请入门 Makefile
Golang Gin实践 番外 请入门 Makefile 原文地址:Golang Gin实践 番外 请入门 Makefile 前言 含一定复杂度的软件工程,基本上都是先编译 A,再依赖 B,再编译 C ...
- golang(gin框架),基于RESTFUL的跨语言远程通信尝试
golang(gin框架),基于RESTFUL的跨语言远程通信尝试 背景: 在今年的项目实训过程中,遇到了这样的问题: 企业老师讲课实用的技术栈是Java springboot. 实训实际给我们讲课以 ...
- 前端程序员学习 Golang gin 框架实战笔记之一开始玩 gin
原文链接 我是一名五六年经验的前端程序员,现在准备学习一下 Golang 的后端框架 gin. 以下是我的学习实战经验,记录下来,供大家参考. https://github.com/gin-gonic ...
- gin项目部署到服务器并后台启动
前言 我们写好的gin项目想要部署在服务器上,我们应该怎么做呢,接下来我会详细的讲解一下部署教程. 1.首先我们要有一台虚拟机,虚拟机上安装好go框架. 2.将写好的项目上传到虚拟机上. 3.下载好项 ...
- 项目集成swagger,并暴露指定端点给swagger
项目集成swagger 一:思考: 1.swagger解决了我们什么问题? 传统开发中,我们在开发完成一个接口后,为了测试我们的接口,我们通常会编写单元测试,以测试我们的接口的可用性,或者用postm ...
随机推荐
- 洛谷 P3695 CYaRon!语 题解 【模拟】【字符串】
大模拟好啊! 万一远古计算机让我写个解释器还真是得爆零了呢. 题目背景 「千歌です」(我是千歌).「曜です」(我是曜).「ルビィです」(我是露比).「3人合わせて.We are CYaRon! よろし ...
- 112th LeetCode Weekly Contest Validate Stack Sequences
Given two sequences pushed and popped with distinct values, return true if and only if this could ha ...
- Oracle之q操作符
Oracle本身默认的是单引号,但是在大家写存储过程或者写SQL语句时,有时候需要拼SQL或者是SQL的值里需要传入含单引号的值,此时就需要使用两个单引号''''来进行转义,其实oracle本身提供了 ...
- Union Find - 20181102 - 20181105
Union Find: 589. Connecting Graph public class ConnectingGraph { //父节点数组 private int[] father = null ...
- jar 启动关闭
1.后台启动 startTest.sh #设置工程路径project_path=/root/testcd $project_path#nohup后台启动,输出日志到test.lognohup java ...
- Intellij IDEA 添加项目依赖
https://blog.csdn.net/TaooLee/article/details/51305443 idea导入一个maven项目 https://blog.csdn.net/qq_3837 ...
- c语言3种方式实现参数传递
学习计算机已经两年了,参数传递已经成功恶心了我两年,今天在写二叉树遍历的时候成功对此忍无可忍.本文是在阅读https://blog.csdn.net/u013097971/article/detail ...
- oracle sql命令
set time on; 设置时间 alter table flashback_test enable row movement; 开启行移 select * from flashback_test ...
- mysql DCl语句
DCl 语句主要书DBA用来管理系统中的对象权限使用 grant select,insert on sakila.* 'kingle'@'localhost' identified by '123'; ...
- mongoDB--万能的$关键字
之前哥的博客写了增删改查的基本用法,其中$set是关键字用来修改值的,但是不关只有set这一个关键字,下面我们就来说一个万能的$关键字 1.常见的等于 大于 小于 大于等于 小于等于 #等于---&g ...