# gin-api **Repository Path**: OrzR3/gin-api ## Basic Information - **Project Name**: gin-api - **Description**: 基于gin和gorm开发基于数据库的api - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-20 - **Last Updated**: 2024-09-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 基于gin和gorm开发基于数据库的api gin官网 https://github.com/gin-gonic/gin 官网例子 ```js package main import ( "net/http" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/ping", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "message": "pong", }) }) r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") } ``` 新建项目文件夹 gin-api 初始化 go.mod go mod init github.com/orzr3/gin-api 安装 gin go get -u github.com/gin-gonic/gin 路由的注册,抽象出来 安装 air go get github.com/air-verse/air ``` go get -u github.com/air-verse/air ``` ``` go get github.com/air-verse/air ``` 集成 gorm 访问数据库 gorm官网 https://gorm.io/zh_CN/docs/index.html 安装 go get -u gorm.io/gorm go get -u gorm.io/driver/sqlite ``` go get -u gorm.io/gorm ``` ``` go get -u gorm.io/driver/sqlite ``` 连接到数据库 https://gorm.io/zh_CN/docs/connecting_to_the_database.html go env -w CGO_ENABLED=1 ``` go env -w CGO_ENABLED=1 ``` 更换GORM默认SQLite驱动出现的问题解决分析 更换GORM默认的SQLite驱动 https://www.jb51.net/jiaoben/3147895tu.htm github.com/glebarez/sqlite go get -u github.com/glebarez/sqlite ``` go get -u github.com/glebarez/sqlite ``` 查询