Gin使用 encoding/json作为默认的json包,但你可以在构建的时候通过tags
去使用jsoniter
API示例
使用 GET,POST,PUT,PATCH,DELETE,OPTIONS
get 示例
package main
import (
"github.com/gin-gonic/gin"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
func main() {
router:= gin.Default()
router.GET("/hello/get",helloGet)
// 端口如果不设定,默认使用:8080 除非定义了 PORT 环境变量
router.Run("localhost:3000")
}
func helloGet( c *gin.Context){
c.JSON(200,gin.H{
"message":"Hello World!",
})
}
2. path 中可设定参数
示例如下
package main
import (
"github.com/gin-gonic/gin"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
func main() {
router:= gin.Default()
router.GET("/hello/get/:name",helloGet)
// 端口如果不设定,默认使用:8080 除非定义了 PORT 环境变量
router.Run("