当前位置:网站首页>[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 !
边栏推荐
- Count the number of various characters in the string
- Qt的connect函数和disconnect函数
- Openshift deployment application
- 2022/2/13 summary
- 【Go实战基础】gin 如何验证请求参数
- C# 将网页保存为图片(利用WebBrowser)
- [staff] time mark and note duration (staff time mark | full note rest | half note rest | quarter note rest | eighth note rest | sixteenth note rest | thirty second note rest)
- History of Web Technology
- 《统计学习方法》——第五章、决策树模型与学习(上)
- Minecraft group service opening
猜你喜欢

整理秒杀系统的面试必备!!!

机器学习之数据类型案例——基于朴素贝叶斯法,用数据辩男女

Matplotlib剑客行——容纳百川的艺术家教程

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

Shengshihaotong and Guoao (Shenzhen) new energy Co., Ltd. build the charging pile industry chain

C4D quick start tutorial - Chamfer

WSL安装、美化、网络代理和远程开发

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

Redis安装部署(Windows/Linux)

What is the future value of fluorite mine of karaqin Xinbao Mining Co., Ltd. under zhongang mining?
随机推荐
C4D quick start tutorial - C4d mapping
oracle删除表空间及用户
[staff] common symbols of staff (Hualian clef | treble clef | bass clef | rest | bar line)
图像变换,转置
【Go实战基础】gin 高效神器,如何将参数绑定到结构体
Redis zadd导致的一次线上问题排查和处理
gocv opencv exit status 3221225785
Minecraft插件服开服
Web技术发展史
CSDN Q & A_ Evaluation
随笔:RGB图像颜色分离(附代码)
What is the future value of fluorite mine of karaqin Xinbao Mining Co., Ltd. under zhongang mining?
gocv图片读取并展示
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
C Baidu map, Gaode map, Google map (GPS) longitude and latitude conversion
Synchronize files using unison
京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
Cloud computing in my eyes - PAAS (platform as a service)
libusb的使用
Qunhui NAS configuring iSCSI storage



