当前位置:网站首页>【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
菜鸟实战,持续学习!
边栏推荐
- PCL calculates the intersection of three mutually nonparallel planes
- Minecraft插件服开服
- gocv图片读取并展示
- kubernetes部署loki日志系统
- gocv边界填充
- Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
- Sqli labs (post type injection)
- Connect function and disconnect function of QT
- Qt的connect函数和disconnect函数
- cmd窗口中中文呈现乱码解决方法
猜你喜欢

Synchronize files using unison

Solid principle: explanation and examples

Shengshihaotong and Guoao (Shenzhen) new energy Co., Ltd. build the charging pile industry chain

CSDN Q & A_ Evaluation

Redis安装部署(Windows/Linux)

KubeSphere 虚拟化 KSV 安装体验

C language - Blue Bridge Cup - 7 segment code

Linux二进制安装Oracle Database 19c

Minecraft安装资源包

Realization of basic function of sequence table
随机推荐
Dip1000 implicitly tagged with fields
C# 高德地图 根据经纬度获取地址
commands out of sync. did you run multiple statements at once
CSDN Q & A_ Evaluation
Data asset management function
Mysql安装时mysqld.exe报`应用程序无法正常启动(0xc000007b)`
OpenShift 部署应用
Sentinel 简单使用
Win10 uses docker to pull the redis image and reports an error read only file system: unknown
MYSQL安装出现问题(The service already exists)
Hengyuan cloud_ Can aiphacode replace programmers?
Openfeign is easy to use
libusb的使用
Avoid breaking changes caused by modifying constructor input parameters
将一串数字顺序后移
C Baidu map, Gaode map, Google map (GPS) longitude and latitude conversion
gocv拆分颜色通道
Judge whether it is Sudoku
gocv图片裁剪并展示
汉诺塔问题的求解与分析
