当前位置:网站首页>[go practical basis] how to bind and use URL parameters in gin
[go practical basis] how to bind and use URL parameters in gin
2022-07-02 09:08:00 【Novice practice】
Catalog
3、 ... and 、 Rookie actual combat
One 、 brief introduction
This article is used to introduce gin How to bind and use url Parameters
Two 、 Knowledge point
- gin route
- Parameter binding and mapping
- obtain url Parameters
- According to the parameters , Return the obtained parameter data
- Universal binding
3、 ... and 、 Rookie actual combat
Actual combat scene : use gin How to bind and use url Parameters
Make arrangements now !
1、 establish go file
package main
// Import package
import (
"fmt"
"runtime"
"github.com/gin-gonic/gin"
)
// The main function
func main() {
// Print using built-in functions
println("Hello", " Rookie actual combat ")
println(" Actual combat scene : ", "gin How to bind and use url Parameters ")
// initialization
r := gin.Default()
// Add routing parameters and callbacks
r.GET("/:name/:id", func(c *gin.Context) {
// Back to code and Corresponding structure information
c.JSON(200, gin.H{
"name": c.Param("name"),
"id": c.Param("id"),
})
})
// Universal binding
r.GET("/user/*action", func(c *gin.Context) {
// Back to code and Corresponding structure information
c.String(200, " Hit the universal binding routing rule \n")
})
// Use package functions to print
fmt.Printf(" edition : %s \n", runtime.Version())
// Start the framework program , Default 8080 port
r.Run()
}
// curl Verification mode
// curl -X GET "http://127.0.0.1:8080/tom/5"
// curl -X GET "http://127.0.0.1:8080/user/addaction"
// curl -X GET "http://127.0.0.1:8080/user/updateaction"
2、 Running results
Hello Rookie actual combat
Actual combat scene : gin How to bind and use url Parameters
[GIN-debug] Listening and serving HTTP on :8080
// Add routing parameters and callbacks
// Universal binding
Rookie actual combat , Continuous learning !
边栏推荐
- Gocv image reading and display
- 【Go实战基础】gin 如何验证请求参数
- [staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the
- How to realize asynchronous programming in a synchronous way?
- Qt——如何在QWidget中设置阴影效果
- Redis sorted set data type API and application scenario analysis
- Cartoon rendering - average normal stroke
- Redis zadd导致的一次线上问题排查和处理
- 队列管理器running状态下无法查看通道
- libusb的使用
猜你喜欢
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
【Go实战基础】如何安装和使用 gin
Shengshihaotong and Guoao (Shenzhen) new energy Co., Ltd. build the charging pile industry chain
ORA-12514问题解决方法
[staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the
Minecraft空岛服开服
Matplotlib剑客行——没有工具用代码也能画图的造型师
Talk about the secret of high performance of message queue -- zero copy technology
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
OpenShift 容器平台社区版 OKD 4.10.0部署
随机推荐
gocv opencv exit status 3221225785
【Go实战基础】gin 如何自定义和使用一个中间件
Finishing the interview essentials of secsha system!!!
QT qtimer class
Webflux responsive programming
ORA-12514问题解决方法
Mysql安装时mysqld.exe报`应用程序无法正常启动(0xc000007b)`
C call system sound beep~
Linux binary installation Oracle database 19C
PCL calculates the intersection of three mutually nonparallel planes
QT drag event
gocv opencv exit status 3221225785
History of Web Technology
Gocv image reading and display
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
[staff] common symbols of staff (Hualian clef | treble clef | bass clef | rest | bar line)
【Go实战基础】如何安装和使用 gin
Kubedm deploys kubernetes v1.23.5 cluster
选择排序和插入排序
Solution and analysis of Hanoi Tower problem