当前位置:网站首页>[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 !
边栏推荐
- Minecraft插件服开服
- commands out of sync. did you run multiple statements at once
- Shengshihaotong and Guoao (Shenzhen) new energy Co., Ltd. build the charging pile industry chain
- Qt QTimer类
- Mysql安装时mysqld.exe报`应用程序无法正常启动(0xc000007b)`
- gocv opencv exit status 3221225785
- Kubedm deploys kubernetes v1.23.5 cluster
- [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
- Flink-使用流批一体API统计单词数量
- Sentinel reports failed to fetch metric connection timeout and connection rejection
猜你喜欢

Dix ans d'expérience dans le développement de programmeurs vous disent quelles compétences de base vous manquez encore?

Installing Oracle database 19C RAC on Linux

Minecraft模组服开服

Kubernetes deploys Loki logging system

During MySQL installation, mysqld Exe reports that the application cannot start normally (0xc000007b)`

Linux binary installation Oracle database 19C

聊聊消息队列高性能的秘密——零拷贝技术

History of Web Technology

C nail development: obtain all employee address books and send work notices

【Go实战基础】gin 如何获取 GET 和 POST 的请求参数
随机推荐
C#钉钉开发:取得所有员工通讯录和发送工作通知
远程连接IBM MQ报错AMQ4036解决方法
【Go实战基础】gin 高效神器,如何将参数绑定到结构体
Qunhui NAS configuring iSCSI storage
C Gaode map obtains the address according to longitude and latitude
C language - Blue Bridge Cup - 7 segment code
【Go实战基础】gin 如何绑定与使用 url 参数
Talk about the secret of high performance of message queue -- zero copy technology
Gocv image reading and display
oracle删除表空间及用户
整理秒杀系统的面试必备!!!
Kubesphere virtualization KSV installation experience
《统计学习方法》——第五章、决策树模型与学习(上)
小米电视不能访问电脑共享文件的解决方案
使用IBM MQ远程连接时报错AMQ 4043解决思路
Installing Oracle database 19C for Linux
Minecraft install resource pack
Image transformation, transpose
汉诺塔问题的求解与分析
选择排序和插入排序

