当前位置:网站首页>[go practical basis] how to set the route in gin
[go practical basis] how to set the route in gin
2022-07-02 09:08:00 【Novice practice】
Catalog
3、 ... and 、 Rookie actual combat
One 、 brief introduction
Actual combat scene : How to use gin Set the routing
Two 、 Knowledge point
- gin The framework starts
- Basic routing
- http get / post request
- return character string string data
3、 ... and 、 Rookie actual combat
Actual combat scene : Use gin Set the routing
Make arrangements now !
1、 establish go file
/*
* @Author: Rookie actual combat
* @Description: gin How to set the route
*/
// Knowledge point :
// # gin The framework starts
// # Basic routing
// # http GET / POST request
// # return character string String data
package main
// Import package
import (
"fmt"
"github.com/gin-gonic/gin"
"runtime"
)
// The main function
func main() {
// Print using built-in functions
println("Hello", " Rookie actual combat ")
println(" Actual combat scene : ", "gin How to set the route ")
// initialization
r := gin.Default()
// add to get Routing and callback
r.GET("/get", func(c *gin.Context) {
// Back to code and String returns
c.String(200, " This is a get Method \n")
})
// add to post Routing and callback
r.POST("/post", func(c *gin.Context) {
// Back to code and String returns
c.String(200, " This is a post Method \n")
})
// add to delete Routing and callback
r.Handle("DELETE", "/delete", func(c *gin.Context) {
// Back to code and String returns
c.String(200, " This is a delete Method \n")
})
// add to any Routing and callback
r.Any("/any", func(c *gin.Context) {
// Back to code and String returns
c.String(200, " This is a any Method \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/get"
// curl -X POST "http://127.0.0.1:8080/post"
// curl -X DELETE "http://127.0.0.1:8080/delete"
// curl -X GET "http://127.0.0.1:8080/any"
// curl -X POST "http://127.0.0.1:8080/any"
// curl -X PUT "http://127.0.0.1:8080/any"
2、 Running results
Hello Rookie actual combat
Actual combat scene : gin How to set the route
[GIN-debug] Listening and serving HTTP on :8080
// add to get Routing and callback
// add to post Routing and callback
// add to delete Routing and callback
// add to any Routing and callback
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
- C language - Blue Bridge Cup - 7 segment code
- Tensorflow2 keras 分类模型
- C4D quick start tutorial - C4d mapping
- 《统计学习方法》——第五章、决策树模型与学习(上)
- Use of libusb
- Mysql安装时mysqld.exe报`应用程序无法正常启动(0xc000007b)`
- oracle删除表空间及用户
- 1、 QT's core class QObject
- Minecraft install resource pack
猜你喜欢
2022/2/13 summary
Linux binary installation Oracle database 19C
【Go实战基础】如何安装和使用 gin
我服了,MySQL表500W行,居然有人不做分区?
Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
There is a problem with MySQL installation (the service already exists)
cmd窗口中中文呈现乱码解决方法
【Go实战基础】gin 高效神器,如何将参数绑定到结构体
随机推荐
Connect function and disconnect function of QT
Leetcode sword finger offer brush questions - day 22
整理秒杀系统的面试必备!!!
gocv opencv exit status 3221225785
【Go实战基础】gin 如何绑定与使用 url 参数
Matplotlib剑客行——没有工具用代码也能画图的造型师
Count the number of various characters in the string
C# 将网页保存为图片(利用WebBrowser)
2022/2/13 summary
Qt的右键菜单
远程连接IBM MQ报错AMQ4036解决方法
Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
Dix ans d'expérience dans le développement de programmeurs vous disent quelles compétences de base vous manquez encore?
京东高级工程师开发十年,编写出:“亿级流量网站架构核心技术”
What is the future value of fluorite mine of karaqin Xinbao Mining Co., Ltd. under zhongang mining?
libusb的使用
C# 百度地图,高德地图,Google地图(GPS) 经纬度转换
Tensorflow2 keras 分类模型
gocv opencv exit status 3221225785
C#钉钉开发:取得所有员工通讯录和发送工作通知