当前位置:网站首页>【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
菜鸟实战,持续学习!
边栏推荐
- OpenShift 容器平台社区版 OKD 4.10.0部署
- Pclpy projection filter -- projection of point cloud to cylinder
- Getting started with k8s: building MySQL with Helm
- Oracle修改表空间名称以及数据文件
- Openshift container platform community okd 4.10.0 deployment
- CSDN Q & A_ Evaluation
- D interface and domain problems
- Count the number of various characters in the string
- Tcp/ip - transport layer
- 选择排序和插入排序
猜你喜欢

Detailed explanation of NIN network

Function ‘ngram‘ is not defined

Nacos 下载启动、配置 MySQL 数据库

KubeSphere 虚拟化 KSV 安装体验

2022/2/13 summary

Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it

Minecraft群組服開服

群辉 NAS 配置 iSCSI 存储

Win10 uses docker to pull the redis image and reports an error read only file system: unknown

Application of kotlin - higher order function
随机推荐
[blackmail virus data recovery] suffix Crylock blackmail virus
Service de groupe minecraft
Linux安装Oracle Database 19c RAC
判断是否是数独
QT drag event
Sqli labs level 1
gocv图片裁剪并展示
C call system sound beep~
Sqli labs Level 2
Hengyuan cloud_ Can aiphacode replace programmers?
Webflux responsive programming
History of Web Technology
[flask] ORM one-to-one relationship
一个经典约瑟夫问题的分析与解答
Openfeign is easy to use
Gocv split color channel
Don't spend money, spend an hour to build your own blog website
Mysql安装时mysqld.exe报`应用程序无法正常启动(0xc000007b)`
OpenFeign 简单使用
CSDN Q & A_ Evaluation
