下载安装go,eclipse配置go
-
Path = %GOROOT%\bin
-
打开cmd验证
# 查看版本
C:\Users\ychen>go version
go version go1.20.6 windows/amd64
# 查看环境变量
C:\Users\ychen>echo %GOPATH%
C:\work\go\library;C:\work\go\workspace
C:\Users\ychen>echo %GOROOT%
C:\Program Files\go
- 配置环境
# 开启mod模式
C:\Users\ychen>go env -w GO111MODULE=on
# 设置七牛镜像源
C:\Users\ychen>go env -w GOPROXY=https://goproxy.cn,direct
# 设置阿里镜像源
C:\Users\ychen>go env -w GOPROXY=https://mirrors.aliyun.com/goproxy
# 关闭包的MD5校验
C:\Users\ychen>go env -w GOSUMDB=off
# 查看环境变量
C:\Users\ychen>go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\ychen\AppData\Local\go-build
set GOENV=C:\Users\ychen\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\work\go\library\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\work\go\library;C:\work\go\workspace
set GOPRIVATE=
set GOPROXY=https://mirrors.aliyun.com/goproxy
set GOROOT=C:\Program Files\go
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.6
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\ychen\AppData\Local\Temp\go-build858386835=/tmp/go-build -gno-record-gcc-switches
- 方式2,离线安装
- 下载GoClipse插件压缩包,解压到一个固定位置
点击查看详情
- 重启软件
>> Running: "C:\Program Files\go\bin\go.exe" get -u github.com/nsf/gocode
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
^^^ Terminated, exit code: 1 ^^^
>> Running: "C:\Program Files\go\bin\go.exe" get -u golang.org/x/tools/cmd/guru
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
^^^ Terminated, exit code: 1 ^^^
>> Running: "C:\Program Files\go\bin\go.exe" get -u github.com/rogpeppe/godef
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
^^^ Terminated, exit code: 1 ^^^
- 解决方案
# 下载压缩包到本地
github.com/nsf/gocode
github.com/rogpeppe/godef
github.com/golang/tools
- 解压后放到如下目录,build命令创建,将生成的gocode.exe/guru.exe/godef.exe移动到C:\Program Files\go\bin
C:\Program Files\go\src\gocode
C:\Program Files\go\src\vendor\golang.org\x\tools\cmd\guru
C:\Program Files\go\src\vendor\godef
- 创建失败
点击查看详情
- 报错1
$ go build vendor/golang.org/x/tools/cmd/guru
go: finding module for package golang.org/x/mod/module
go: finding module for package golang.org/x/mod/semver
vendor\golang.org\x\tools\internal\imports\mod.go:20:2: cannot query module due
to -mod=vendor
(Go version in go.mod is at least 1.14 and vendor directory exists.)
vendor\golang.org\x\tools\internal\gocommand\vendor.go:17:2: cannot query module
due to -mod=vendor
(Go version in go.mod is at least 1.14 and vendor directory exists.)
- 报错2
$ go build vendor/godef
go: finding module for package golang.org/x/mod/semver
go: finding module for package github.com/rogpeppe/godef/go/parser
go: finding module for package 9fans.net/go/acme
go: finding module for package github.com/rogpeppe/godef/go/ast
go: finding module for package github.com/rogpeppe/godef/go/printer
go: finding module for package github.com/rogpeppe/godef/go/types
go: finding module for package github.com/rogpeppe/godef/go/token
vendor\godef\acme.go:11:2: cannot query module due to -mod=vendor
(Go version in go.mod is at least 1.14 and vendor directory exists.)
vendor\godef\adapt.go:20:2: cannot query module due to -mod=vendor
(Go version in go.mod is at least 1.14 and vendor directory exists.)
vendor\godef\godef.go:24:2: cannot query module due to -mod=vendor
(Go version in go.mod is at least 1.14 and vendor directory exists.)
vendor\godef\adapt.go:21:2: cannot query module due to -mod=vendor
(Go version in go.mod is at least 1.14 and vendor directory exists.)
vendor\godef\godef.go:25:2: cannot query module due to -mod=vendor
(Go version in go.mod is at least 1.14 and vendor directory exists.)
vendor\godef\adapt.go:22:2: cannot query module due to -mod=vendor
(Go version in go.mod is at least 1.14 and vendor directory exists.)
vendor\golang.org\x\tools\internal\gocommand\vendor.go:17:2: cannot query module
due to -mod=vendor
(Go version in go.mod is at least 1.14 and vendor directory exists.)
- 解决方案
方式1:使用低版本的go
方式2:删除自带vendor重建依赖
- 具体步骤
# 创建gocode
C:\Program Files\go\src
λ go build gocode
# 重建依赖
C:\Program Files\go\src
λ mv vendor ${GOPATH}
C:\Program Files\go\src
λ go mod tidy
go: downloading golang.org/x/net v0.22.0
go: downloading golang.org/x/crypto v0.21.0
go: downloading golang.org/x/sys v0.18.0
go: downloading golang.org/x/text v0.14.0
$GOPATH/golang.org/x/crypto/chacha20: malformed import path "$GOPATH/golang.org/x/crypto/chacha20": invalid char '$'
$GOPATH/golang.org/x/crypto/chacha20poly1305: malformed import path "$GOPATH/golang.org/x/crypto/chacha20poly1305": invalid char '$'
$GOPATH/golang.org/x/crypto/cryptobyte: malformed import path "$GOPATH/golang.org/x/crypto/cryptobyte": invalid char '$'
$GOPATH/golang.org/x/crypto/cryptobyte/asn1: malformed import path "$GOPATH/golang.org/x/crypto/cryptobyte/asn1": invalid char '$'
$GOPATH/golang.org/x/crypto/hkdf: malformed import path "$GOPATH/golang.org/x/crypto/hkdf": invalid char '$'
$GOPATH/golang.org/x/crypto/internal/alias: malformed import path "$GOPATH/golang.org/x/crypto/internal/alias": invalid char '$'
$GOPATH/golang.org/x/crypto/internal/poly1305: malformed import path "$GOPATH/golang.org/x/crypto/internal/poly1305": invalid char '$'
$GOPATH/golang.org/x/net/dns/dnsmessage: malformed import path "$GOPATH/golang.org/x/net/dns/dnsmessage": invalid char '$'
$GOPATH/golang.org/x/net/http/httpguts: malformed import path "$GOPATH/golang.org/x/net/http/httpguts": invalid char '$'
$GOPATH/golang.org/x/net/http/httpproxy: malformed import path "$GOPATH/golang.org/x/net/http/httpproxy": invalid char '$'
$GOPATH/golang.org/x/net/http2/hpack: malformed import path "$GOPATH/golang.org/x/net/http2/hpack": invalid char '$'
$GOPATH/golang.org/x/net/idna: malformed import path "$GOPATH/golang.org/x/net/idna": invalid char '$'
$GOPATH/golang.org/x/net/lif: malformed import path "$GOPATH/golang.org/x/net/lif": invalid char '$'
$GOPATH/golang.org/x/net/nettest: malformed import path "$GOPATH/golang.org/x/net/nettest": invalid char '$'
$GOPATH/golang.org/x/net/route: malformed import path "$GOPATH/golang.org/x/net/route": invalid char '$'
$GOPATH/golang.org/x/sys/cpu: malformed import path "$GOPATH/golang.org/x/sys/cpu": invalid char '$'
$GOPATH/golang.org/x/text/secure/bidirule: malformed import path "$GOPATH/golang.org/x/text/secure/bidirule": invalid char '$'
$GOPATH/golang.org/x/text/transform: malformed import path "$GOPATH/golang.org/x/text/transform": invalid char '$'
$GOPATH/golang.org/x/text/unicode/bidi: malformed import path "$GOPATH/golang.org/x/text/unicode/bidi": invalid char '$'
$GOPATH/golang.org/x/text/unicode/norm: malformed import path "$GOPATH/golang.org/x/text/unicode/norm": invalid char '$'
C:\Program Files\go\src
λ go mod vendor
$GOPATH/golang.org/x/crypto/chacha20: malformed import path "$GOPATH/golang.org/x/crypto/chacha20": invalid char '$'
$GOPATH/golang.org/x/crypto/chacha20poly1305: malformed import path "$GOPATH/golang.org/x/crypto/chacha20poly1305": invalid char '$'
$GOPATH/golang.org/x/crypto/cryptobyte: malformed import path "$GOPATH/golang.org/x/crypto/cryptobyte": invalid char '$'
$GOPATH/golang.org/x/crypto/cryptobyte/asn1: malformed import path "$GOPATH/golang.org/x/crypto/cryptobyte/asn1": invalid char '$'
$GOPATH/golang.org/x/crypto/hkdf: malformed import path "$GOPATH/golang.org/x/crypto/hkdf": invalid char '$'
$GOPATH/golang.org/x/crypto/internal/alias: malformed import path "$GOPATH/golang.org/x/crypto/internal/alias": invalid char '$'
$GOPATH/golang.org/x/crypto/internal/poly1305: malformed import path "$GOPATH/golang.org/x/crypto/internal/poly1305": invalid char '$'
$GOPATH/golang.org/x/net/dns/dnsmessage: malformed import path "$GOPATH/golang.org/x/net/dns/dnsmessage": invalid char '$'
$GOPATH/golang.org/x/net/http/httpguts: malformed import path "$GOPATH/golang.org/x/net/http/httpguts": invalid char '$'
$GOPATH/golang.org/x/net/http/httpproxy: malformed import path "$GOPATH/golang.org/x/net/http/httpproxy": invalid char '$'
$GOPATH/golang.org/x/net/http2/hpack: malformed import path "$GOPATH/golang.org/x/net/http2/hpack": invalid char '$'
$GOPATH/golang.org/x/net/idna: malformed import path "$GOPATH/golang.org/x/net/idna": invalid char '$'
$GOPATH/golang.org/x/net/lif: malformed import path "$GOPATH/golang.org/x/net/lif": invalid char '$'
$GOPATH/golang.org/x/net/nettest: malformed import path "$GOPATH/golang.org/x/net/nettest": invalid char '$'
$GOPATH/golang.org/x/net/route: malformed import path "$GOPATH/golang.org/x/net/route": invalid char '$'
$GOPATH/golang.org/x/sys/cpu: malformed import path "$GOPATH/golang.org/x/sys/cpu": invalid char '$'
$GOPATH/golang.org/x/text/secure/bidirule: malformed import path "$GOPATH/golang.org/x/text/secure/bidirule": invalid char '$'
$GOPATH/golang.org/x/text/transform: malformed import path "$GOPATH/golang.org/x/text/transform": invalid char '$'
$GOPATH/golang.org/x/text/unicode/bidi: malformed import path "$GOPATH/golang.org/x/text/unicode/bidi": invalid char '$'
$GOPATH/golang.org/x/text/unicode/norm: malformed import path "$GOPATH/golang.org/x/text/unicode/norm": invalid char '$'
# 安装依赖
C:\Program Files\go\src
λ go get -u -v github.com/rogpeppe/godef
go: downloading 9fans.net/go v0.0.4
go: downloading golang.org/x/sys v0.18.0
go: zip: not a valid zip file
go: zip: not a valid zip file
# 解决方案
C:\Program Files\go\src
λ go clean -modcache
C:\Program Files\go\src
λ go env -w GOPROXY="https://goproxy.cn,direct"
# 重新安装依赖
C:\Program Files\go\src
λ go get -u -v github.com/rogpeppe/godef
go: downloading github.com/rogpeppe/godef v1.1.2
go: downloading 9fans.net/go v0.0.0-20181112161441-237454027057
go: downloading golang.org/x/tools v0.1.12
go: downloading 9fans.net/go v0.0.4
go: downloading golang.org/x/tools v0.19.0
go: downloading golang.org/x/sys v0.3.0
go: downloading golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
go: downloading golang.org/x/net v0.4.1-0.20230214201333-88ed8ca3307d
go: downloading golang.org/x/mod v0.16.0
go: downloading golang.org/x/sys v0.18.0
go: downloading golang.org/x/net v0.22.0
go: downloading golang.org/x/crypto v0.21.0
go: downloading golang.org/x/text v0.14.0
go: added 9fans.net/go v0.0.4
go: added github.com/rogpeppe/godef v1.1.2
go: upgraded golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a => v0.21.0
go: upgraded golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 => v0.16.
0
go: upgraded golang.org/x/net v0.4.1-0.20230214201333-88ed8ca3307d => v0.22.0
go: upgraded golang.org/x/sys v0.3.0 => v0.18.0
go: upgraded golang.org/x/text v0.5.0 => v0.14.0
go: upgraded golang.org/x/tools v0.1.12 => v0.19.0
# 创建godef
C:\Program Files\go\src
λ go build godef
# 创建guru
C:\Program Files\go\src
λ go build golang.org/x/tools/cmd/guru
-
移动到如下目录
-
配置eclipse
-
创建项目,File -> New -> Go Project -> 选择GOPATH文件夹
-
下载gdb64.exe,移动到C:\Program Files\go\bin目录,参考
-
打印
-
报错:Resource doesn't have a corresponding Go package
-
报错:Executable file () doesnt exist.
# cmd进入go所在目录,使用命名运行成功
C:\work\go\workspace\demo\src\main
λ go run new_file.go
Hello
# 创建
C:\work\go\workspace\demo\src\main
λ go build new_file.go
# 生成new_file.exe,修改为main.exe后,移动到项目bin文件夹下
C:\work\go\workspace\demo\src\main
λ ls
new_file.exe* new_file.go
- 再次使用eclipse执行,执行成功