当前位置:网站首页>【Golang】安装 iris 的方法
【Golang】安装 iris 的方法
2022-06-28 15:58:00 【e1373773】
根据 iris 在 github 上的官方文档,结合自己在安装时的过程,现在总结一下 iris 的安装方法。
1. 创建工作目录
mkdir myapp2. 进入工作目录
cd myapp3. 初始化 myapp 的 mod
go mod init myapp4. 从 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.go6. 写入以下代码
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.go8. 打开浏览器,输入 main.go 里的示例 URL
http://localhost:8080/welcome
9. 参考链接
边栏推荐
- 首次失败后,爱美客第二次冲刺港交所上市,财务负责人变动频繁
- Ffmpeg forbidden output banner log (30)
- 如何查询数据库中一个表中的所有数据呢?
- openGauss内核:SQL解析过程分析
- Opengauss kernel: analysis of SQL parsing process
- leetcode:22. bracket-generating
- PostgreSQL enables grouping statistics by year, month, day, week, hour, minute and second
- GAIN的代码实现(4)——基于GAN的Spam数据集缺失数据填补(序)【改进版】
- tablestore中可以使用sql查询可以查出表中所有的数据吗?
- Interviewer: how does the thread pool reuse threads? Do you know? Tell me about it
猜你喜欢

openGauss内核:SQL解析过程分析

A 24-year-old bald programmer teaches you how to continuously integrate and deliver microservice delivery. You can't learn how to cut me off

10:00面试,10:02就出来了 ,问的实在是太...

VS2013 帮助文档中没有 win32/com

leetcode:22. bracket-generating

【Hot100】4. 寻找两个正序数组的中位数

Etcd可视化工具:Kstone简介(一)

征文投稿丨使用轻量应用服务器搭建博客环境

QT create 5.0.3 configuring qt4.8.7

The first place on the list - brake by wire "new cycle", the market competitiveness of local suppliers is TOP10
随机推荐
成功迁移到云端需要采取的步骤
leetcode:22. bracket-generating
Today's sleep quality record is 80 points
Visual Studio 2019软件安装包和安装教程
Knowing these commands allows you to master shell's own tools
Naacl 2022 | distillation of machinetranslation SOTA model
Slim gain (sgain) introduction and code implementation -- missing data filling based on generated countermeasure network
IPDK — Overview
【高并发基础】MySQL索引优化
逆向调试入门-PE结构详解02/07
简单介绍一下tensorflow与pytorch的相互转换(主要是tensorflow转pytorch)
[recommendation system] esmm model of multi task learning (updating)
平台即代码的未来是Kubernetes扩展
The Web3.0 era is coming. See how Tianyi cloud storage resources invigorate the system to enable new infrastructure (Part 1)
Visual Studio 2010 compilation qt5.6.3
A little hesitant in the morning
国债与定期存款哪个更安全 两者之间有何区别
24岁秃头程序员教你微服务交付下如何持续集成交付,学不会砍我
Sample explanation of batch inserting data using MySQL bulkloader
Deep learning convolutional neural network of machine learning to realize handwritten font recognition based on CNN network