# backlog-server **Repository Path**: YR-YR/backlog-server ## Basic Information - **Project Name**: backlog-server - **Description**: todolist-server端,使用go开发 - **Primary Language**: Go - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-03-29 - **Last Updated**: 2024-05-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Golang Server ## 项目初始化 `go mod init ToDoList` ## 安装依赖 ```shell # gin go get -u github.com/gin-gonic/gin # viper日志 go get -u github.com/spf13/viper # 数据库和gorm go get -u gorm.io/driver/mysql go get -u gorm.io/gorm # uuid go get -u github.com/google/uuid # token go get -u github.com/golang-jwt/jwt/v5 # 邮箱 go get github.com/jordan-wright/email # swagger go get -u github.com/swaggo/swag/cmd/swag go install github.com/swaggo/swag/cmd/swag@latest go get -u github.com/swaggo/files go get -u github.com/swaggo/gin-swagger # 日志 go get -u go.uber.org/zap # base64验证码 go get -u github.com/mojocn/base64Captcha # gokit 工具集合 go get github.com/songzhibin97/gkit # 阿里云oss go get -u github.com/aliyun/aliyun-oss-go-sdk # websocket go get -u github.com/gorilla/websocket # cron定时任务 go get github.com/robfig/cron/v3@v3.0.0 ``` ## 搭建项目目录 ![img.png](img.png) [docker-compose.yaml](..%2Fdeploy%2Fdocker-compose%2Fdocker-compose.yaml) ## 集成Swagger 1.[swagger注释格式参考文档](https://github.com/swaggo/swag/blob/master/README.md#declarative-comments-format) 2.安装wager `go install github.com/swaggo/swag/cmd/swag@latest` 3.添加注释在main.go中main函数上以及控制器 ```go // @title To-Do-List Swagger API接口文档 // @version v1.0 // @description 待办事项 // @termsOfService http://swagger.io/terms/ // @contact.name cwy // @contact.url http://www.swagger.io/support // @contact.email support@swagger.io // @BasePath / func main() {} // 控制器上 // Login // @Tags Base // @Summary 用户登录 // @Produce application/json // @Param data body request.Login true "用户名, 密码, 验证码" // Success 200 {object} response.LoginRes{data=response.LoginRes,msg=string} "返回包括用户信息,token,过期时间" // @Router /user/login [post] func (receiver *userApi) Login(c *gin.Context) {} ``` 4.初始化swagger ` swag init -g main.go -o ./docs` 可以看到根目录下生成了docs其中包含三个swagger必备文件。 ![img_1.png](img_1.png) 5. 打开`http://localhost:8329/[这里写main函数中的BasePath]/swagger/index.html` ## 定时任务 [文档](https://github.com/robfig/cron) ## 自动生成dockerfile ```shell go install github.com/zeromicro/go-zero/tools/goctl@latest goctl docker --go main.go ``` ``` docker run -p 3306:3306 --name backlog-container -v /Users/lihaha/Desktop/mr_yu/codes/backlog/mysql_v:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=backlog -e -d 5d2fb452c483 ``` docker-compose -f docker-compose.yaml up --build