当前位置:网站首页>【Golang】安装 iris 的方法
【Golang】安装 iris 的方法
2022-06-28 15:58:00 【e1373773】
根据 iris 在 github 上的官方文档,结合自己在安装时的过程,现在总结一下 iris 的安装方法。
1. 创建工作目录
mkdir myapp
2. 进入工作目录
cd myapp
3. 初始化 myapp 的 mod
go mod init myapp
4. 从 github 上获取 iris
go get github.com/kataras/iris/[email protected]
- 国内的代理服务器可能与 github 通信失败,所以可以更换代理服务器。(for Windows10)
go env -w GOPROXY="https://goproxy.io"
5. 安装完成后,创建第一个 main.go 文件
vim main.go
6. 写入以下代码
package main
import (
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
// 输出html
// 请求方式: GET
// 访问地址: http://localhost:8080/welcome
app.Handle("GET", "/welcome", func(ctx iris.Context) {
ctx.HTML("<h1>Welcome</h1>")
})
// 输出字符串
// 类似于 app.Handle("GET", "/ping", [...])
// 请求方式: GET
// 请求地址: http://localhost:8080/ping
app.Get("/ping", func(ctx iris.Context) {
ctx.WriteString("pong")
})
// 输出json
// 请求方式: GET
// 请求地址: http://localhost:8080/hello
app.Get("/hello", func(ctx iris.Context) {
ctx.JSON(iris.Map{"message": "Hello Iris!"})
})
app.Run(iris.Addr(":8080")) //8080 监听端口
}
7. 编译并运行 main.go
go run main.go
8. 打开浏览器,输入 main.go 里的示例 URL
http://localhost:8080/welcome
9. 参考链接
边栏推荐
- 【Spock】处理 Non-ASCII characters in an identifier
- 昨日元宇宙|Meta “元宇宙”部门一季度亏损29.6亿美元,六福珠宝发行数字藏品
- 【高并发基础】MySQL索引优化
- 机器学习之卷积神经网络使用cifar10数据集和alexnet网络模型训练分类模型,安装labelimg,以及报错ERROR
- CODING DevOps 助力中化信息打造新一代研效平台,驱动“线上中化”新未来
- Super automation and the future of network security
- 10 years of testing experience, worthless in the face of the physiological age of 35
- Convolutional neural networks for machine learning -- an introduction to CNN
- 超自动化与网络安全的未来
- 成功迁移到云端需要采取的步骤
猜你喜欢
Knowing these commands allows you to master shell's own tools
【初学者必看】vlc实现的rtsp服务器及转储H264文件
The sadness of software testers is Their own technical ability can not meet the requirements of large manufacturers?
NAACL 2022 | 机器翻译SOTA模型的蒸馏
Visual studio 2019 software installation package and installation tutorial
10: 00 interview, came out at 10:02, the question is really too
Azure Kinect微软摄像头Unity开发小结
有哪些好用的供应商管理系统
QT create 5.0.3 configuring qt4.8.7
Opengauss kernel: analysis of SQL parsing process
随机推荐
A new 25K byte from the Department showed me what the ceiling is
【Hot100】2.两数相加
Qt5.5.1 configuring msvc2010 compiler and WinDbg debugger
What is the maximum number of concurrent TCP connections for a server? 65535?
IPDK — Overview
【Spock】处理 Non-ASCII characters in an identifier
Geoffrey Hinton:我的五十年深度学习生涯与研究心法
ID卡复制教程(使用T5577卡复制4100卡)
What are the most powerful small and medium-sized companies in Beijing?
开源技术交流丨一站式全自动化运维管家ChengYing入门介绍
Steps to be taken for successful migration to the cloud
机器学习之卷积神经网络Lenet5训练模型
Qt5.5.1配置MSVC2010编绎器和windbg调试器
昨日元宇宙|Meta “元宇宙”部门一季度亏损29.6亿美元,六福珠宝发行数字藏品
Traffic management and control of firewall Foundation
FFmpeg之禁止输出banner log(三十)
访中国信通院王蕴韬:数实融合赋能文化产业繁荣发展
[recommendation system] esmm model of multi task learning (updating)
A little hesitant in the morning
国债与定期存款哪个更安全 两者之间有何区别