当前位置:网站首页>[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 !
边栏推荐
- Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
- libusb的使用
- [staff] time sign and note duration (full note | half note | quarter note | eighth note | sixteenth note | thirty second note)
- 聊聊消息队列高性能的秘密——零拷贝技术
- Gocv boundary fill
- 队列的基本概念介绍以及典型应用示例
- Synchronize files using unison
- MYSQL安装出现问题(The service already exists)
- Openshift build image
- 以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化
猜你喜欢

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

commands out of sync. did you run multiple statements at once

【Go实战基础】gin 如何获取 GET 和 POST 的请求参数

Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system

Linux二进制安装Oracle Database 19c

Solution and analysis of Hanoi Tower problem

Don't spend money, spend an hour to build your own blog website

京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别

Installing Oracle database 19C RAC on Linux

Talk about the secret of high performance of message queue -- zero copy technology
随机推荐
Introduction to the basic concept of queue and typical application examples
C# 调用系统声音 嘀~
[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
Qunhui NAS configuring iSCSI storage
Linux二进制安装Oracle Database 19c
【Go实战基础】gin 如何设置路由
Matplotlib剑客行——初相识Matplotlib
分布式服务架构精讲pdf文档:原理+设计+实战,(收藏再看)
Servlet全解:继承关系、生命周期、容器和请求转发与重定向等
Select sort and insert sort
十年开发经验的程序员告诉你,你还缺少哪些核心竞争力?
C language - Blue Bridge Cup - 7 segment code
gocv图片裁剪并展示
NPOI 导出Word 字号对应
【Go实战基础】gin 如何验证请求参数
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
Redis zadd导致的一次线上问题排查和处理
Minecraft模组服开服
Linux安装Oracle Database 19c
Function ‘ngram‘ is not defined

