how to use Goland with module-aware go

With module aware go the GOPATH semantics are gone, replaced with a separate root source tree approach.

I was using Goland pointing at GOPATH and thus any 'go get' would add a package to my environment and index. Also any 'go install's would show an executable in GOPATH/bin within the same environment.

With module aware go, what is the intended user story for Goland? Have each module root as a  separate Goland environment?

1
6 comments

Hi Theodore,

Sorry, I didn't understand your question. What do you mean by GoLand environment and what is module aware go?

0
go 1.11 has a module-aware mode. When the env var GO111MODULE is set to on, 'go get' behavior becomes driven by go.mod file. This represents a very different way of working with source trees than the traditional GOPATH method of the go tools. 
 
So my question is, when I enable vgo with Goland, how should I now use Goland given that GOPATH is no longer the organizing principle of dependent packages and the behavior of the go tools.
0

> So my question is, when I enable vgo with Goland

Settings | Go | Go Modules

> This represents a very different way of working with source trees than the traditional GOPATH method of the go tools. 

You still need a GOPATH since Go Modules subsystem stores dependencies there. But it's not required for GoLand to index entire GOPATH sources. You can disable it in the `Settings | Go | GOPATH | Index entire GOPATH`.
 
> how should I now use Goland given that GOPATH is no longer the organizing principle of dependent packages and the behavior of the go tools.
 
No special rules as soon as Go Modules are enabled for a project. GoLand will invoke `go list` automatically to get and index all dependencies of your project.
 
0
Avatar
Permanently deleted user

I need some clarification to Go Modules subsystem in Goland.

I've started project in my local directory and I'm able to run it with go run command without any problem, but Goland cannot resolve project dependencies. Apparently my Goland setup isn't correct but I cannot figure out what is wrong.
Project root have src and pkg directories. Here's my source file src/go-grpc-course/greet/greet_server/server.go
I'm running following command in terminal: go run greet/greet_server/server.go
in <project root>/src/go-grpc-course directory 

I've setup project GOPATH in Goland to point to same GOPATH as I have in terminal.
I've enabled Go Modules (vgo) integration.
What should I do to resolve this problem in Goland?

Here's Goland output when I run server.go file:

GOROOT=/usr/local/Cellar/go/1.12.7/libexec #gosetup
GOPATH=/Users/<username>/development/projects/grpc/grpc-golang-master-class-build-modern-api-and-microservices #gosetup
/usr/local/Cellar/go/1.12.7/libexec/bin/go build -o /private/var/folders/j2/tjzvrxdx0qz7ll5cl0q_mnq00000gn/T/___go_build_go_grpc_course_greet_greet_server /Users/<username>/development/projects/grpc/grpc-golang-master-class-build-modern-api-and-microservices/src/go-grpc-course/greet/greet_server/server.go #gosetup
go: cannot determine module path for source directory /Users/<username>/development/projects/grpc/grpc-golang-master-class-build-modern-api-and-microservices (outside GOPATH, no import comments)

Compilation finished with exit code 1

Here's my go env output in terminal:
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/<username>/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/<username>/development/projects/grpc/grpc-golang-master-class-build-modern-api-and-microservices"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j2/tjzvrxdx0qz7ll5cl0q_mnq00000gn/T/go-build941352753=/tmp/go-build -gno-record-gcc-switches -fno-common"



0

Eduard,

> go: cannot determine module path for source directory 

This means that the compilation working directory doesn't contain any go.mod file. Could you share your run configuration, please? What if you try to run entire package instead of single file?

0
Avatar
Permanently deleted user

@Alexander Zolotov

Indeed, go.mod is missing. I've disabled Go Modules (vgo) integration and after that Goland is able to resolve dependencies.
I have to read more about Go Modules then.
Thank you.

0

Please sign in to leave a comment.