33 lines
525 B
Go
33 lines
525 B
Go
package main
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
//gin 的hello world
|
|
|
|
func main() {
|
|
//1.创建路由
|
|
|
|
// 默认使用了两个中间件 Logger(), Recovery()
|
|
r := gin.Default()
|
|
|
|
//r:=gin.New() //也可以创建不带中间件的路由
|
|
|
|
//2.绑定路由规则
|
|
//gin.Context 封装了request和response
|
|
r.GET("/", func(c *gin.Context) {
|
|
c.String(http.StatusOK, "Hello world")
|
|
})
|
|
r.POST("/post", post)
|
|
r.PUT("/put")
|
|
|
|
//3.监听端口 默认在8080
|
|
r.Run(":8000")
|
|
}
|
|
|
|
func post(c *gin.Context) {
|
|
|
|
}
|