golang goland 模組設定,提示找不到目錄
阿新 • • 發佈:2020-08-19
working directory is not part of a module
程式碼參考: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.
作者:日落_3d9f
連結:https://www.jianshu.com/p/fb9a947ac8f3
來源:簡書
著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。