代码参考:https://www.studyiris.com/doc/irisDoc/Installation.html
package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
app.Get("/", func(ctx iris.Context){})
app.Run(iris.Addr(":8080"))
}
报错如下:
main.go:2:8: cannot find module providing package github.com/kataras/iris: working directory is not part of a module
包的依赖我已经下载好了,存放到$GOPATH/pkg/mod下(注意有github.com就放到github.com目录下)。
一直无非解决,直到这篇文字:https://www.jianshu.com/p/c666ebdb462b
一般网上的资料都是建议在工程的根目录下执行go mod init projectName命令。在执行go mod化之后,所有的引用都不再是以GOPATH为相对路径的引用了,而是变成了以go.mod中初始化的项目名为起始的引用。
$ go mod init main
go: creating new go.mod: module main
$ ls
go.mod main.go
$ go run main.go
go: finding module for package github.com/kataras/iris/v12
go: found github.com/kataras/iris/v12 in github.com/kataras/iris/v12 v12.1.8
go: finding module for package github.com/shurcooL/sanitized_anchor_name
go: found github.com/shurcooL/sanitized_anchor_name in github.com/shurcooL/sanitized_anchor_name v1.0.0
Now listening on: http://localhost:8080
Application started. Press CMD+C to shut down.