Go workspace on Windows 10

I have been having this issue of setting up my workspace for a while now. I have two values in my GOPATH. They are C:\Users\Me\Documents\gocodes\ and C:\Users\Me\Documents\gocodes\src\github.com\dan-osineye\ “so I have my project saved here”. When I do the go run for my .go file it runs and I get a good result, but that is almost useless. The image shows my what I have been going through for days now. Really frustrating.

I’d appreciate a step by step procedure, I don’t mind reinstalling go all over. I don’t mind having a session with a pro. Or is Windows awkward for go?

It is best to set a single folder as your GOPATH.

If C:\Users\DANNY\Documents\gocodes will be that folder then do the following.

Set this environmental variable
GOPATH=C:\Users\DANNY\Documents\gocodes

Then at the end of your PATH variable add this:
%GOPATH%\bin

Now close down all your terminal windows and restart a new one
Navigate to the gocodes folder
Add a single folder called src
I would remove anything else that may exist inside of gocodes. Make a backup of that.

execute the go env command from the terminal and you should see your Go env show up. Check that the GOPATH variable is set with your full gocodes folder

The src folder begins your go workspace. This is where you want to work from. To test things, we can go get something.

go get -u github.com/ardanlabs/gotraining

When this finishes you should have this material on disk

cd %GOPATH\src\github.com/ardanlabs/gotraining

It is best to start new projects with a repo first and to clone that repo inside your Go workspace but any folder inside the src folder is enough to get started.

Look at this as well:
http://www.goinggo.net/2013/06/installing-go-gocode-gdb-and-liteide.html

3 Likes

If you are in the directory above gowebapp, then issue the command

 go build ./gowebapp

Note the relative syntax. This is because the go tool works on import path names, that is names relative to $GOPATH/src.

Another way to do what you want is to use the fully qualified import path of your package

go build github.com/dan-osineye/gowebapp

Lastly if you are inside $GOPATH/src/github.com/dan-osineye/gowebapp then you can issue

go build

Without supplying an import path to build the source code in the current directory.

You should also research the difference between go build and go install, go build is usually not the tool you want.

1 Like

Thanks a lot that was really heplful, it works well now.

For my personal projects, which is preferable. To save each project folder in GOPATH/src or GOPATH/src/github.com/my_git_account?
Cheers.

Alright, thanks. The link was helpful.

The latter. I recommend reading https://golang.org/doc/code.html

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.