当前位置:网站首页>【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
菜鸟实战,持续学习!
边栏推荐
- Kubesphere virtualization KSV installation experience
- Minecraft plug-in service opening
- Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
- Data asset management function
- 统计字符串中各类字符的个数
- 群辉 NAS 配置 iSCSI 存储
- Multi version concurrency control mvcc of MySQL
- Pclpy projection filter -- projection of point cloud to cylinder
- Redis安装部署(Windows/Linux)
- Kubernetes deploys Loki logging system
猜你喜欢

Minecraft group service opening

Solution of Xiaomi TV's inability to access computer shared files

OpenShift 部署应用

OpenShift构建镜像

Web技术发展史

Installing Oracle database 19C RAC on Linux

Minecraft群组服开服

What is the future value of fluorite mine of karaqin Xinbao Mining Co., Ltd. under zhongang mining?

Redis安装部署(Windows/Linux)

Introduction to the basic concept of queue and typical application examples
随机推荐
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
将一串数字顺序后移
C language implementation of mine sweeping game
OpenShift构建镜像
Linux安装Oracle Database 19c RAC
Gateway is easy to use
gocv图片读取并展示
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
Sentinel easy to use
KubeSphere 虚拟化 KSV 安装体验
gocv拆分颜色通道
Sqli labs level 12
C# 调用系统声音 嘀~
Sqli labs Level 2
Tcp/ip - transport layer
Analysis and solution of a classical Joseph problem
[blackmail virus data recovery] suffix Crylock blackmail virus
Qt的拖动事件
Sqli labs level 1
Avoid breaking changes caused by modifying constructor input parameters
