使用Handle方法统一处理http请求
package main
import "github.com/gin-gonic/gin"
func main() {
app := gin.Default()
app.Handle("GET", "/page1", func(context *gin.Context) {
context.Writer.Write([]byte("this is page 1"))
})
app.Handle("POST", "/page2", func(context *gin.Context) {
context.Writer.Write([]byte("this is page 2"))
})
app.Run()
}
使用Gin的分类处理来处理http请求
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
app := gin.Default()
app.GET("/page1", func(context *gin.Context) {
context.Writer.Write([]byte("this is page 1"))
})
app.POST("/page2", func(context *gin.Context) {
context.Writer.Write([]byte("this is page 2"))
})
app.Run()
}
网友评论