当前位置:网站首页>【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
菜鸟实战,持续学习!
边栏推荐
- Sentinel 简单使用
- Qt QTimer类
- 寻找链表中值域最小的节点并移到链表的最前面
- Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
- 使用递归函数求解字符串的逆置问题
- Openshift deployment application
- 小米电视不能访问电脑共享文件的解决方案
- Image transformation, transpose
- C language - Blue Bridge Cup - 7 segment code
- Analysis and solution of a classical Joseph problem
猜你喜欢
![[blackmail virus data recovery] suffix Hydra blackmail virus](/img/27/f44334cf98229d0f8b33c70a878ca8.jpg)
[blackmail virus data recovery] suffix Hydra blackmail virus

History of Web Technology

Data asset management function

Introduction to the basic concept of queue and typical application examples

Synchronize files using unison

Gateway is easy to use

OpenShift 部署应用

C language - Blue Bridge Cup - 7 segment code

OpenFeign 簡單使用

Nacos 下载启动、配置 MySQL 数据库
随机推荐
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
C4D quick start tutorial - Chamfer
gocv边界填充
Chrome debugging
Honeypot attack and defense drill landing application scheme
Linux binary installation Oracle database 19C
Zipkin is easy to use
2022/2/14 summary
Minecraft module service opening
gocv opencv exit status 3221225785
D interface and domain problems
kubeadm部署kubernetes v1.23.5集群
选择排序和插入排序
Pyspark de duplication dropduplicates, distinct; withColumn、lit、col; unionByName、groupBy
OpenFeign 简单使用
MYSQL安装出现问题(The service already exists)
Openshift build image
Gocv image cutting and display
Minecraft安装资源包
Call Stack
