make 时报错如下:
–> Building…
go build -v -o bin/xenon --ldflags ‘-X “build.tag=v1.1.4-10-ga6a055c” -X “build.time=2021/06/04 02:23:12” -X “build.git=a6a055c”’ src/xenon/xenon.go
src/xenon/xenon.go:12:2: package build is not in GOROOT (/usr/lib/golang/src/build)
src/xenon/xenon.go:13:2: package config is not in GOROOT (/usr/lib/golang/src/config)
src/xenon/xenon.go:18:2: package raft is not in GOROOT (/usr/lib/golang/src/raft)
src/xenon/xenon.go:19:2: package server is not in GOROOT (/usr/lib/golang/src/server)
src/xenon/xenon.go:20:2: package xbase/xlog is not in GOROOT (/usr/lib/golang/src/xbase/xlog)
make: *** [build] Error 1
go env 查看环境(默认)
GO111MODULE=""
GOARCH=“amd64”
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH=“amd64”
GOHOSTOS=“linux”
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS=“linux”
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY=“https://proxy.golang.org,direct”
GOROOT="/usr/lib/golang"
GOSUMDB=“sum.golang.org”
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION=“go1.16.4”
GCCGO=“gccgo”
AR=“ar”
CC=“gcc”
CXX=“g++”
CGO_ENABLED=“1”
GOMOD="/dev/null"
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-build1930421392=/tmp/go-build -gno-record-gcc-switches"
如果要用 gopath 模式 引入包 从src目录下开始引入 需要关闭 go mod 模式
export GO111MODULE=off
[root@slave1 xenon]# make
–> Building…
go build -v -o bin/xenon --ldflags ‘-X “build.tag=v1.1.4-10-ga6a055c” -X “build.time=2021/06/04 02:33:20” -X “build.git=a6a055c”’ src/xenon/xenon.go
model
build
vendor/github.com/pkg/errors
vendor/github.com/stretchr/testify/vendor/github.com/pmezard/go-difflib/difflib
vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew
xbase/xlog
vendor/github.com/go-sql-driver/mysql
config
xbase/common
xbase/xrpc
vendor/github.com/stretchr/testify/assert
mysqld
mysql
raft
server
command-line-arguments
go build -v -o bin/xenoncli --ldflags ‘-X “build.tag=v1.1.4-10-ga6a055c” -X “build.time=2021/06/04 02:33:20” -X “build.git=a6a055c”’ src/cli/cli.go
vendor/github.com/mattn/go-runewidth
vendor/github.com/spf13/pflag
vendor/github.com/olekukonko/tablewriter
cli/callx
vendor/github.com/spf13/cobra
cli/cmd
command-line-arguments
如果使用go mod 模式
export GO111MODULE=on
并且在目录下执行 go mod init
目录下产生两个文件
go.mod
go.sum
否则就会报错
main.go:15:2: package tinybg/conf is not in GOROOT (/usr/local/go/src/tinybg/conf)
main.go:16:2: package tinybg/utils is not in GOROOT (/usr/local/go/src/tinybg/utils)
参考:https://www.jianshu.com/p/82b55b516cc8
十分感谢!