Go 包不存在于 $GOROOT 目录下
时间:2024-02-14
浏览:143
作者:佚名
知识点掌握了,还需要不断练习才能熟练运用。下面golang学习网给大家带来一个Golang开发实战,手把手教大家学习《Go 包不存在于 $GOROOT 目录下》,在实现功能的过程中也带大家重新温习相关知识点,温故而知新,回头看看说不定又有不一样的感悟!
问题内容
我使用以下 go 模块来构建应用程序:
github.com/martinlindhe/unit
现在,go 代码非常简单;我只是想为实际工作设置环境:
import(
"fmt"
"unit"
)
foo := unit.fromfahrenheit(100)
fmt.println("100 fahrenheit in celsius = ", foo.celsius())
在 go.mod 中:
go 1.17 require github.com/martinlindhe/unit v0.0.0-20210313160520-19b60e03648d
执行 go build 或 go get 结果:
package 单元不在 goroot (/usr/local/cellar/go/1.17/libexec/src/unit)
运行 go mod download 执行时没有错误。 go.sum 文件似乎是正确的,所有必要的依赖项都存在。
环境是最新版本的 vs code,go 在 macos big sur 11.5.2 上通过 homebrew 安装
我肯定遗漏了一些明显的东西。我编写的其他应用程序没有遇到此问题。
正确答案
导入路径不正确。 Playground。
package main
import (
"fmt"
"github.com/martinlindhe/unit"
)
func main() {
foo := unit.FromFahrenheit(100)
fmt.Println("100 fahrenheit in celsius = ", foo.Celsius())
}
以上就是《Go 包不存在于 $GOROOT 目录下》的详细内容,更多关于的资料请关注golang学习网公众号!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.20
11.20
11.20
11.20
热门专题
