vue+gin—— GetcharZp
- vue+gin—— GetcharZp
- P1-项目介绍【03:51】
- P2-项目梳理【29:59】
- P3-环境搭建【05:27】
- P4-整合GIN、GORM【16:20】
- P5-整合 Swagger【10:01】
- P6-接口-问题列表【19:34】
- P7-接口-问题详情【24:06】
- P8-接口-用户详情【05:36】
- P9-接口-提交列表【20:02】
- P10-接口-用户登录【26:09】
- P11-接口-发送验证码 [引入jordan-wright/email]【12:28】
- P12-接口-用户注册 [引入go-redis、go-uuid]【36:57】
- P13-接口-用户排行榜【07:36】
- P14-核心-代码执行器【11:04】
- P15-接口-问题创建、认证中间件【35:32】
- P16-接口-分类列表【09:01】
- P17-接口-分类的新增、修改、删除【17:03】
- P18-接口-问题修改【29:06】
- P19-接口-代码的提交及判断(重点)【28:33】
- P20-接口-代码的提交及判断(补充)【09:49】
vue+gin—— GetcharZp
P1-项目介绍【03:51】
P2-项目梳理【29:59】
problem
user
category
submit
P3-环境搭建【05:27】
go env
默认 1.18 开启
初始化 go mod init
整理 go mod tidy
gorm
gin
P4-整合GIN、GORM【16:20】
gin
router/app.go
service/ping.go
gorm 安装 mysql
mysql 测试
models / init.go
models / problem.go
service / problem.go
router / app.go
P5-整合 Swagger【10:01】
https://github.com/swaggo/gin-swagger
go get -u github.com/swaggo/swag/cmd/swag
swag init
作者讲解 怎么安装 ,首先删除 swag
第一次 安装 直接执行 没有用
在swap/main.go 中 go install
bin 目录下生成
查看版本 swag -v
go get -u github.com/swaggo/gin-swagger
go get -u github.com/swaggo/files
使用 导入包
import the docs like this: I assume your project named github.com/go-project-name/docs.
docs "github.com/go-project-name/docs"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
package main
import (
"github.com/gin-gonic/gin"
docs "github.com/go-project-name/docs"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"net/http"
)
// @BasePath /api/v1
// PingExample godoc
// @Summary ping example
// @Schemes
// @Description do ping
// @Tags example
// @Accept json
// @Produce json
// @Success 200 {string} Helloworld
// @Router /example/helloworld [get]
func Helloworld(g *gin.Context) {
g.JSON(http.StatusOK,"helloworld")
}
func main() {
r := gin.Default()
docs.SwaggerInfo.BasePath = "/api/v1"
v1 := r.Group("/api/v1")
{
eg := v1.Group("/example")
{
eg.GET("/helloworld",Helloworld)
}
}
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
r.Run(":8080")
}
配置 地址
import the docs 改 为 自己的 项目名
docs 报错 因为 没有 执行swag init
swag init
验证
localhost:8080/swagger/index.html
swag 使用
try it out
Execute