当前位置:网站首页>[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 !
边栏推荐
- win10使用docker拉取redis镜像报错read-only file system: unknown
- Redis sorted set data type API and application scenario analysis
- C Gaode map obtains the address according to longitude and latitude
- [staff] common symbols of staff (Hualian clef | treble clef | bass clef | rest | bar line)
- 统计字符串中各类字符的个数
- 我服了,MySQL表500W行,居然有人不做分区?
- Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
- Count the number of various characters in the string
- Essay: RGB image color separation (with code)
- Cartoon rendering - average normal stroke
猜你喜欢

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

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

【Go实战基础】gin 高效神器,如何将参数绑定到结构体

C language implementation of mine sweeping game

十年開發經驗的程序員告訴你,你還缺少哪些核心競爭力?

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

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

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

Servlet全解:继承关系、生命周期、容器和请求转发与重定向等

Redis安装部署(Windows/Linux)
随机推荐
gocv拆分颜色通道
Linux安装Oracle Database 19c RAC
Don't spend money, spend an hour to build your own blog website
Tensorflow2 keras classification model
NPOI 导出Word 字号对应
QT qtimer class
判断是否是数独
【Go实战基础】gin 如何设置路由
C4D quick start tutorial - C4d mapping
Solution of Xiaomi TV's inability to access computer shared files
During MySQL installation, mysqld Exe reports that the application cannot start normally (0xc000007b)`
【Go实战基础】gin 如何自定义和使用一个中间件
Judge whether it is Sudoku
There is a problem with MySQL installation (the service already exists)
Finishing the interview essentials of secsha system!!!
ORA-12514问题解决方法
一、Qt的核心类QObject
Shengshihaotong and Guoao (Shenzhen) new energy Co., Ltd. build the charging pile industry chain
寻找链表中值域最小的节点并移到链表的最前面
分布式服务架构精讲pdf文档:原理+设计+实战,(收藏再看)

