【发布时间】:2021-12-10 17:50:48
【问题描述】:
我正在使用 1.14.2 版本的 go。我正在尝试将我的项目添加到 go.mod 以使用 go mod init <dependecyname> 部署 heroku。之后我尝试使用go run main.go 命令运行我的项目,但收到以下错误:
go: finding module for package github.com/googollee/go-socket.io
go: finding module for package github.com/dgrijalva/jwt-go
go: finding module for package github.com/gorilla/mux
go: found github.com/dgrijalva/jwt-go in github.com/dgrijalva/jwt-go v3.2.0+incompatible
go: found github.com/googollee/go-socket.io in github.com/googollee/go-socket.io v1.4.4
go: found github.com/gorilla/mux in github.com/gorilla/mux v1.8.0
controllers/userController.go:10:2: cannot find package
models/avatar.go:3:8: cannot find package
models/base.go:6:1: cannot find package
models/base.go:7:1: cannot find package
models/user.go:8:2: cannot find package
controllers/userController.go:11:2: cannot find package
controllers/userController.go:12:2: cannot find package
controllers/userController.go:13:2: cannot find package
当我调查我的go.mod 文件时,我意识到require 块中存在未解决的依赖错误:
module <modulename>
go 1.14
require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/googollee/go-socket.io v1.4.4 // indirect
github.com/gorilla/mux v1.8.0 // indirect
)
如何解决?
【问题讨论】:
-
1.您的模块必须(此处不争论)一个正确的模块名称。使用你喜欢的任何东西,但
<modulename>无效。如果您不确定要使用什么,请使用“example.org/experiment”。 2.您必须(这里不再争论)通过正确的(阅读:完整)导入路径导入模块中的包:例如“example.org/experiment/models”,或者您如何命名它们。 3. 阅读如何编写 Go 代码并坚持下去。 4.go mod init必须用模块名来调用,而不是一些依赖。 5. 切勿将go run与文件名参数一起使用。 -
我假设作者使用占位符来表示模块名称和依赖项,而不是上面的值。
-
@Ali Gurelli 你能解决这个问题吗?
-
@sgauri 是的,但我不记得如何