当前位置:网站首页>[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 !
边栏推荐
- 京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
- Minecraft模组服开服
- Programmers with ten years of development experience tell you, what core competitiveness do you lack?
- 2022/2/13 summary
- C# 高德地图 根据经纬度获取地址
- Hengyuan cloud_ Can aiphacode replace programmers?
- NPOI 导出Word 字号对应
- Kubernetes deploys Loki logging system
- QT qtimer class
- QT drag event
猜你喜欢
京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
C language implementation of mine sweeping game
汉诺塔问题的求解与分析
【Go实战基础】gin 如何设置路由
Talk about the secret of high performance of message queue -- zero copy technology
There is a problem with MySQL installation (the service already exists)
Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
Nacos download, start and configure MySQL database
Don't spend money, spend an hour to build your own blog website
C nail development: obtain all employee address books and send work notices
随机推荐
win10使用docker拉取redis镜像报错read-only file system: unknown
oracle修改数据库字符集
Minecraft安装资源包
机器学习之数据类型案例——基于朴素贝叶斯法,用数据辩男女
远程连接IBM MQ报错AMQ4036解决方法
「Redis源码系列」关于源码阅读的学习与思考
QT qtimer class
1、 QT's core class QObject
Gocv boundary fill
History of Web Technology
使用递归函数求解字符串的逆置问题
统计字符串中各类字符的个数
2022/2/13 summary
【Go实战基础】如何安装和使用 gin
Talk about the secret of high performance of message queue -- zero copy technology
京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
Hengyuan cloud_ Can aiphacode replace programmers?
Qt的connect函数和disconnect函数
Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions