当前位置:网站首页>[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 !
边栏推荐
- Aneng logistics' share price hit a new low: the market value evaporated by nearly 10 billion yuan, and it's useless for chairman Wang Yongjun to increase his holdings
- Solution of Xiaomi TV's inability to access computer shared files
- Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
- Redis zadd导致的一次线上问题排查和处理
- gocv边界填充
- 使用递归函数求解字符串的逆置问题
- [staff] common symbols of staff (Hualian clef | treble clef | bass clef | rest | bar line)
- Installing Oracle database 19C RAC on Linux
- 京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
- Mysql安装时mysqld.exe报`应用程序无法正常启动(0xc000007b)`
猜你喜欢

《统计学习方法》——第五章、决策树模型与学习(上)

Solution of Xiaomi TV's inability to access computer shared files

Data type case of machine learning -- using data to distinguish men and women based on Naive Bayesian method

Matplotlib剑客行——初相识Matplotlib

将一串数字顺序后移

Openshift build image

C#钉钉开发:取得所有员工通讯录和发送工作通知

Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions

Web技术发展史

以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化
随机推荐
聊聊消息队列高性能的秘密——零拷贝技术
QT drag event
Introduction to the basic concept of queue and typical application examples
Minecraft group service opening
WSL安装、美化、网络代理和远程开发
C4D quick start tutorial - Chamfer
gocv拆分颜色通道
C call system sound beep~
Minecraft空岛服开服
Image transformation, transpose
Tensorflow2 keras classification model
CSDN Q & A_ Evaluation
C Gaode map obtains the address according to longitude and latitude
C language - Blue Bridge Cup - 7 segment code
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
Linux安装Oracle Database 19c RAC
Select sort and insert sort
Kubesphere virtualization KSV installation experience
图像变换,转置
C # save web pages as pictures (using WebBrowser)

