Upon learning the basics of go I realise I need this root gocode directory to export as GOPATH, I would much rather simply be able to have a project folder, which I can install packages into, and run my go code from within, is this seriously how they've programmed go to be.. who likes this?
I've looked at the vendor folder option but that still means needing a gocode GOPATH export and the vendor directories need to be in that source folder structure.
I want my project to be the root and that's it. How can that not be possible with go lang?
Or is it?
Yes. You need to set your GOPATH, and all your go-code, -binaries, -packages etc will be placed in this folder. You can make a folder in the root of $GOPATH/src
, e.g $GOPATH/src/myapp
and then create a file within this folder. Example myapp.go
package main
import fmt
func main() {
fmt.Print("My app")
}
Compile it with go install $GOPATH/src/myapp/myapp.go
and run it with $GOPATH/bin/myapp
.