The question is in the title: Is there a GO equivalent to python's virtualenv? What is the prefered work flow to start a new project?
Go modules, which are built into the tooling since Go 1.12 (or 1.11 with a special flag turned on). Create a directory outside of your GOPATH (i.e. basically anywhere), create a go.mod
using go mod init
(which gives your module a declared importpath), and start working. There's no need to "activate" an environment like with venv; the Go 1.12+ tooling will automatically work within the current module when one is detected, e.g. any go get
will happen within module scope.
Although the Go blog entry I linked to mostly focuses on creating a library within a module, which you may want to publish to allow using from elsehwere, this isn't a requirement. You can create a module to hold a program (package main
) as well, and there is no need to publish it (although if you do, it becomes possible to use go get
to install the program).