当前位置:网站首页>【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
菜鸟实战,持续学习!
边栏推荐
- Function ‘ngram‘ is not defined
- Minecraft模组服开服
- gocv图片读取并展示
- Using recursive functions to solve the inverse problem of strings
- Win10 uses docker to pull the redis image and reports an error read only file system: unknown
- Use of libusb
- Npoi export word font size correspondence
- Nacos download, start and configure MySQL database
- Solution of Xiaomi TV's inability to access computer shared files
- Linux安装Oracle Database 19c
猜你喜欢

Avoid breaking changes caused by modifying constructor input parameters

Kubernetes deploys Loki logging system

KubeSphere 虚拟化 KSV 安装体验

win10使用docker拉取redis镜像报错read-only file system: unknown

Minecraft群组服开服

Hengyuan cloud_ Can aiphacode replace programmers?

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

Minecraft群組服開服

Redis安装部署(Windows/Linux)

Minecraft install resource pack
随机推荐
Gocv split color channel
kubeadm部署kubernetes v1.23.5集群
C#钉钉开发:取得所有员工通讯录和发送工作通知
Right click menu of QT
群辉 NAS 配置 iSCSI 存储
Gateway is easy to use
Minecraft group service opening
PCL calculates the intersection of three mutually nonparallel planes
Oracle related statistics
Application of kotlin - higher order function
gocv拆分颜色通道
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
Googlenet network explanation and model building
Openshift build image
Sqli labs level 12
Essay: RGB image color separation (with code)
HackTheBox-Gunship
OpenShift 容器平台社区版 OKD 4.10.0部署
cmd窗口中中文呈现乱码解决方法
查看was发布的应用程序的端口
