I have installed Golang on my Mac with Brew. So it's the latest and greatest. VS Code is up to date. I have installed the most recent Go extensions and ALL of the tools from the command palette.
All this seems to work. However, when I try to reference a utility package, I get no suggestions in VSCode. I assumed it would be smart enough to suggest my local package example.go
. Correct me if that is a false assumption.
Second, since there is no suggestion via intellisense and I manually add the import as github.com/foo/go/obs
it automatically adds a prefix of the package name in front of it resulting in this:
import (
example "github.com/foo/go/obs"
)
Every tutorial I have seen does not have that prefix with the package name. Why is it adding example
in from of the virtual ns? Wondering if there is a configuration I haven't hit yet?
Overall it seems like there are issues referencing packages local or external. Have to close down VSCode and then reopen and it resolves.
I have to have something misconfigured.
Here are is the output of go env
:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/me/Library/Caches/go-build"
GOENV="/Users/me/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/me/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/me/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.17.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.17.5/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/w6/d0mglhnn71x89t_y0hcy5f4w0000gn/T/go-build684279622=/tmp/go-build -gno-record-gcc-switches -fno-common"
I have created a simple project. A main.go
, a go.mod
, and a utility I'd like to reference in the main.go
Here is the file structure:
main.go (before referencing my local package):
package main
func main() {
println("Hello World!")
}
go.mod
module github.com/foo/go
go 1.17
example.go
package example
func Do() {
println("Hello from utility!")
}
main.go (after referencing local package and it adds the prefix of the package name)
package main
import (
example "github.com/foo/go/obs"
)
func main() {
example.Do()
println("Hello World!")
}