# ginbases **Repository Path**: kalaidi/ginbases ## Basic Information - **Project Name**: ginbases - **Description**: Gin - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-07-13 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ginbases #### 介绍 Gin-Bases #### 软件架构 Gin框架0基础 #### 安装教程 1. 无 #### 使用说明 1. 无 #### 特性 1. RESTful API 2. Gorm 3. Swagger 4. logging 5. Jwt-go 6. Gin 7. Graceful restart or stop (fvbock/endless) 8. App configurable 9. Cron 10. Redis #### 参考对象 1. https://github.com/eddycjy 2. https://eddycjy.com/go-categories/ 3. 结构体的beego的form验证和valid验证:`https://beego.me/docs/mvc/controller/validation.md` 4. 结构体的gorm的验证 #### 常用指令 1. go mod init(init go.mod) 2. go mod tidy(update go.mod) 3. curl 127.0.0.1:8000/test(test get api) 4. go run main.go(start server) 5. swag -v 6. swag init 7. go mod vendor(package environment) #### 关于swagger 1. 访问swagger: `localhost:port/swagger/index.html` 2. 返回数组: `@Success 200 {array} models.ArticleResponse` 3. 返回object: `@Success 200 {object} models.ArticleResponse` 4. swag文档地址: `https://swaggo.github.io/swaggo.io/declarative_comments_format/api_operation.html` 5. swag文档地址: `https://github.com/swaggo/swag/blob/master/README_zh-CN.md` #### curl使用 ``` 获取标签列表 curl 127.0.0.1:8000/api/v1/tags 新建标签 curl -X POST --data "" http://127.0.0.1:8000/api/v1/tags\?name\=2\&state\=1\&created_by\=test 更新指定标签 curl -X PUT --data "" http://127.0.0.1:8000/api/v1/tags/1\?name\=edit1\&state\=0\&modified_by\=edit1 删除指定标签 curl -X DELETE http://127.0.0.1:8000/api/v1/tags/1 ``` #### 启动方式 ``` func main() { // 启动方式一: router.run, 返回string, 默认8080端口 router := gin.Default() router.GET("/test", func(c *gin.Context) { c.String(http.StatusOK, "hello gin") }) _ = router.Run() // 启动方式二: 返回json, 同上 router := gin.Default() router.GET("/test", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"name": "jay"}) }) _ = router.Run() // 启动方式三: 返回json, 指定端口 router := gin.Default() router.GET("/test", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "test", }) }) s := &http.Server{ Addr: fmt.Sprintf(":%d", setting.HTTPPort), Handler: router, ReadTimeout: setting.ReadTimeout, WriteTimeout: setting.WriteTimeout, MaxHeaderBytes: 1 << 20, } s.ListenAndServe() } ```