Iris 框架安装
Iris是一个跨平台的软件。
唯一的要求是基于Go编程语言,版本1.14及以上,并开启模块。
$ go env -w GO111MODULE=on
安装
$ go get github.com/kataras/iris/v12@v12.1.8
或者
$ cd your_project_name
$ go mod init
# go.mod
module your_project_name
go 1.14
require (
github.com/kataras/iris/v12 v12.1.8
)
$ go build
如果在安装过程中遇到网络错误,请确保设置了有效的GOPROXY环境变量。
go env -w GOPROXY=https://goproxy.cn,https://gocenter.io,https://goproxy.io,direct
测试
main.go
package main
import "github.com/kataras/iris/v12"
func main() {
app := iris.New()
app.Get("/ping", func(ctx iris.Context) {
ctx.JSON(iris.Map{
"message": "pong",
})
})
app.Listen(":8080")
}
{
"message": "pong"
}
输出看到成功了。
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: