当前位置:网站首页>【Go实战基础】如何安装和使用 gin
【Go实战基础】如何安装和使用 gin
2022-07-02 06:33:00 【菜鸟实战】
目录
一、简介
什么是 Gin ,Gin是一个golang的微框架,封装比较优雅,API友好,源码注释比较明确,具有快速灵活,容错方便等特点
安装: go get -u github.com/gin-gonic/gin
二、知识点
- gin 安装
- gin 启动
- gin 基础路由
- gin 返回 JSON 数据
三、菜鸟实战
实战场景:用 Go 实现安装和使用 gin
马上安排!
1、创建 go文件
/*
* @Author: 菜鸟实战
* @Description: 如何安装和使用 gin
*/
/*
Gin是一个golang的微框架,封装比较优雅,API友好,源码注释比较明确,具有快速灵活,容错方便等特点
安装: go get -u github.com/gin-gonic/gin
*/
// 知识点:
// # gin 安装
// # gin 启动
// # gin 基础路由
// # gin 返回 JSON 数据
package main
// 导入包
import (
"fmt"
"github.com/gin-gonic/gin"
"runtime"
)
// 主函数
func main() {
// 使用内置函数打印
println("Hello", "菜鸟实战")
println("实战场景: ", "如何安装和使用 gin")
// 初始化
r := gin.Default()
// 添加路由和回调
r.GET("/ping", func(c *gin.Context) {
// 返回的 code 和 对应的结构体信息
c.JSON(200, gin.H{
"message": "pong",
})
})
// 使用包函数打印
fmt.Printf("版本: %s \n", runtime.Version())
// 启动框架程序, 默认 8080 端口
r.Run()
}
2、运行结果
Hello 菜鸟实战
实战场景: 如何安装和使用 gin
[GIN-debug] Listening and serving HTTP on :8080
菜鸟实战,持续学习!
边栏推荐
- Sqli labs level 1
- WSL installation, beautification, network agent and remote development
- Gocv image reading and display
- Image transformation, transpose
- Qt的拖动事件
- kubeadm部署kubernetes v1.23.5集群
- 1、 QT's core class QObject
- gocv opencv exit status 3221225785
- Function ‘ngram‘ is not defined
- History of Web Technology
猜你喜欢
Kubesphere virtualization KSV installation experience
During MySQL installation, mysqld Exe reports that the application cannot start normally (0xc000007b)`
Sentinel easy to use
Zipkin is easy to use
kubeadm部署kubernetes v1.23.5集群
commands out of sync. did you run multiple statements at once
Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
Installing Oracle database 19C for Linux
MYSQL安装出现问题(The service already exists)
Honeypot attack and defense drill landing application scheme
随机推荐
Qt——如何在QWidget中设置阴影效果
[blackmail virus data recovery] suffix Rook3 blackmail virus
Zipkin is easy to use
gocv图片读取并展示
Pclpy projection filter -- projection of point cloud to cylinder
Gocv image reading and display
Openfeign facile à utiliser
使用递归函数求解字符串的逆置问题
[blackmail virus data recovery] suffix Hydra blackmail virus
Solution and analysis of Hanoi Tower problem
MYSQL安装出现问题(The service already exists)
Connect function and disconnect function of QT
commands out of sync. did you run multiple statements at once
[blackmail virus data recovery] suffix Crylock blackmail virus
QT qtimer class
Minecraft group service opening
Mysql安装时mysqld.exe报`应用程序无法正常启动(0xc000007b)`
Right click menu of QT
Application of kotlin - higher order function
随笔:RGB图像颜色分离(附代码)