package main
import (
"fmt"
"github.com/gin-gonic/gin"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"log"
)
var db *gorm.DB
var err error
func main() {
r := gin.Default()
dsn := "root:Nexon8888@tcp(127.0.0.1:3306)/iapplus?charset=utf8mb4&parseTime=True&loc=Local"
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err!=nil {
log.Fatal("数据库连接错误")
}
r.GET("/ping/:name", ping)
r.Run("127.0.0.1:8081") // listen and serve on 0.0.0.0:8080
}
func ping(c *gin.Context) {
//c.JSON(200, gin.H{
// "message": "pong",
//})
var user UserModel
db.First(&user)
fmt.Println(user.ID)
fmt.Println(user.Mobile)
c.String(200, "Hello World"+c.Param("name"))
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…