package main import ( "fmt" "github.com/gin-gonic/gin" ) func main() { engine := gin.Default() engine.Handle("GET","/hello", func(context *gin.Context) { name:=context.DefaultQuery("name","hello") fmt.Println(name) context.Writer.Write([]byte("Hello " + name)) }) engine.Handle("POST","/login", func(context *gin.Context) { userName := context.PostForm("user_name") password := context.PostForm("password") fmt.Println(userName) fmt.Println(password) context.Writer.Write([]byte("Hello " + userName)) }) engine.GET("hello_get", func(context *gin.Context) { name := context.Query("name") fmt.Println(name) }) engine.POST("login_post", func(context *gin.Context) { userName, userNameExist := context.GetPostForm("userName") if ! userNameExist { fmt.Println("无用户名") } password, passwordExist := context.GetPostForm("password") if ! passwordExist { fmt.Println("无密码") } fmt.Println(userName) fmt.Println(password) context.Writer.Write([]byte("OK")) }) engine.DELETE("user/:id", func(context *gin.Context) { userId := context.Param("id") fmt.Println(userId) context.Writer.Write([]byte("已删除")) }) err := engine.Run() if err != nil { return } }
gin-router
最新推荐文章于 2024-09-10 21:37:16 发布