gpt4 book ai didi

linux - "Package ... is not in GOROOT "时出现错误 "go run"

转载 作者:行者123 更新时间:2023-12-04 08:19:11 31 4
gpt4 key购买 nike

首先,我想说谢谢你阅读我的主题。我是 Golang 的新手,很高兴收到您的帮助。
我正在为 php-fpm-exporter 使用 golang
(https://github.com/hipages/php-fpm_exporter)
我的环境go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/toandp99/.cache/go-build"
GOENV="/home/toandp99/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/toandp99/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/toandp99/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/toandp99/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build100112555=/tmp/go-build -gno-record-gcc-switches"
当我尝试 php-fpm-exporter
toandp99@toandp99-x555uj:~/php-fpm_exporter$ ls
cmd Dockerfile LICENSE phpfpm README.md
CODE_OF_CONDUCT.md go.mod main.go PHP-FPM.pid sonar-project.properties
config.sh go.sum Makefile PHP-FPM.sh test
toandp99@toandp99-x555uj:~/php-fpm_exporter$ ./PHP-FPM.sh start
Starting Monitoring FastCGI Process Manager...go: downloading github.com/spf13/cobra v0.0.7
go: downloading github.com/speps/go-hashids v2.0.0+incompatible
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/gosuri/uitable v0.0.4
go: downloading github.com/tomasen/fcgi_client v0.0.0-20180423082037-2bb3d819fd19
go: downloading github.com/fatih/color v1.9.0
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/mattn/go-colorable v0.1.6
go: downloading github.com/prometheus/client_golang v1.5.1
go: downloading github.com/mattn/go-runewidth v0.0.8
go: downloading github.com/prometheus/common v0.9.1
go: downloading github.com/prometheus/client_model v0.2.0
go: downloading github.com/cespare/xxhash v1.1.0
go: downloading github.com/prometheus/procfs v0.0.10
go: downloading github.com/golang/protobuf v1.3.4
go: downloading github.com/cespare/xxhash/v2 v2.1.1
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
cmd/server.go:29:2: package client_golang-master/prometheus is not in GOROOT (/home/toandp99/local/go/src/client_golang-master/prometheus)
cmd/server.go:30:2: package client_golang-master/prometheus/promhttp is not in GOROOT (/home/toandp99/local/go/src/client_golang-master/prometheus/promhttp)
cmd/root.go:29:2: package cobra-master is not in GOROOT (/home/toandp99/local/go/src/cobra-master)
cmd/root.go:27:2: package go-homedir is not in GOROOT (/home/toandp99/local/go/src/go-homedir)
cmd/root.go:28:2: package logrus-master is not in GOROOT (/home/toandp99/local/go/src/logrus-master)
cmd/root.go:26:2: package php-fpm_exporter/phpfpm is not in GOROOT (/home/toandp99/local/go/src/php-fpm_exporter/phpfpm)
cmd/root.go:30:2: package viper-master is not in GOROOT (/home/toandp99/local/go/src/viper-master)
在 bash 文件(PHP-FPM.sh)中,我运行这个命令
go run main.go server --web.listen-address $PHP_FPM_WEB_LISTEN_ADDRESS --log.level=$PHP_FPM_LOG_LEVEL --phpfpm.scrape-uri $PHP_FPM_SCRAPE_URI --web.telemetry-path $PHP_FPM_WEB_TELEMETRY_PATH --phpfpm.fix-process-count = $PHP_FPM_FIX_PROCESS_COUNT
我不知道要修复这个错误:(
谢谢 <3

最佳答案

当您的项目不在 GoPATH 中时,通常会发生此错误。要解决此问题,请使用 GO111MODULE=auto (Click here 了解详情)
在 Go 中,项目应该在一个特定的位置(GOPATH)来解决这个问题 Go Modules 出现,它帮助我们在 go 路径之外运行 go 程序。默认情况下,Go 语言使用 GoPATH,您可以通过更改环境变量 GO11MODULE 将其更改为 GoModules到auto (如果您的项目不在 GoPATH 中,将使用 GO 模块)或 on (即使您的项目在 GOPATH 中,也将始终使用 GO 模块)
笔记:
查看您的项目,您似乎已经初始化了 Go 模块(存在 go.mod )这就是为什么我不建议初始化 go 模块(可以通过运行来完成 go mod init )

关于linux - "Package ... is not in GOROOT "时出现错误 "go run",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65572966/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com