当前位置:网站首页>[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 !
边栏推荐
- Redis sorted set data type API and application scenario analysis
- 寻找链表中值域最小的节点并移到链表的最前面
- Kubernetes deploys Loki logging system
- 分布式服务架构精讲pdf文档:原理+设计+实战,(收藏再看)
- 使用递归函数求解字符串的逆置问题
- C language implementation of mine sweeping game
- 【Go实战基础】gin 高效神器,如何将参数绑定到结构体
- Avoid breaking changes caused by modifying constructor input parameters
- 【Go实战基础】gin 如何获取 GET 和 POST 的请求参数
- 一、Qt的核心类QObject
猜你喜欢
Win10 uses docker to pull the redis image and reports an error read only file system: unknown
Introduction to the basic concept of queue and typical application examples
Web技术发展史
Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
Cloud computing in my eyes - PAAS (platform as a service)
C4D quick start tutorial - C4d mapping
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
[staff] time sign and note duration (full note | half note | quarter note | eighth note | sixteenth note | thirty second note)
Multi version concurrency control mvcc of MySQL
Talk about the secret of high performance of message queue -- zero copy technology
随机推荐
Nacos download, start and configure MySQL database
win10使用docker拉取redis镜像报错read-only file system: unknown
【Go实战基础】gin 如何获取 GET 和 POST 的请求参数
Minecraft插件服开服
队列的基本概念介绍以及典型应用示例
Oracle 相关统计
Matplotlib剑客行——没有工具用代码也能画图的造型师
Gocv image cutting and display
Win10 uses docker to pull the redis image and reports an error read only file system: unknown
gocv拆分颜色通道
Tensorflow2 keras classification model
汉诺塔问题的求解与分析
Pyspark de duplication dropduplicates, distinct; withColumn、lit、col; unionByName、groupBy
Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
C nail development: obtain all employee address books and send work notices
Qt的拖动事件
1、 QT's core class QObject
【Go实战基础】如何安装和使用 gin
Minecraft安装资源包
Gocv boundary fill