Author Archives: Lamonte

Creating a Golang 1.11 local project and using local packages (vgo)

So I’ve been googling for a few weeks now trying to understand how to create a simple local application using vgo because it seemed fairly interesting to me. I’ve come across a few stackoverflow questions and the best answer was this one even though it wasn’t fully answering my question.

So if you want to create a local application without the need of using a local repository to create an application which uses other peoples modules then this is the article you’ve been waiting for which is odd how simple it is to accomplish and yet there’s little to no information available online.

So lets get started. First you should Download Golang 1.11 (latest) and make sure golang’s bin is set in your environment.

(Note: You also still need GOPATH to be set for packages to be cached else they will be stored in your user folder, so set a user environment variable for GOPATH to the path where you want your cache to be stored)

Next lets create a new goland vgo project. It’s very simple, load up goland, click New Project, select Go Module (vgo), make sure the project path is where you want your application to be stored and make sure the sdk (path to vgo is select, should be selected by default). I named my project “awesomevgo”.

This will create a go.mod file for you with the name of the module set for you.

(Note: Now if you want to create 3rd party modules, you’d probably want to create it normally then rename the module (so it doesn’t create unnecessary long folder name like ‘z:\blah\bitbucket.com\name’ gotta love vgo because of not needing to do that) to the repo path where it’s hosted like “bitbucket.org/name/reponame”. Then you’d write your module packages specifically for that repo like you would normally)

Creating the application example

Now this section is pretty straight forward. I’m going to show you a visual of what I’m doing, but also type it out for those that will come across this site and my images corrupt or something.

  • Create a subpackage, I called mine ‘example’
  • Create a subpackage file, name it anything you want with a go extension
  • Add the package name to the top of the file (goland does this for you)
  • Create a simple function that’s exported (starts with a capital)
  • Create a main.go file and add package main to the top – goland might try giving it the module name (default package name), ignore that since we want an executable
  • Add your `func main(){}` in there and then start typing out your function name and allow GoLand to auto complete it.
  • If you’re using a different editor or ide that doesn’t understand vgo just add the following import to the type `import “modulename/subpackagename”` then call your subpackage function (subpackage.FunctionName()) inside the main function then build the main script by calling `go build` or `go build main.go` which ever works for you. Or run it using go run ./

Below is a visualization of this which should be easy to distinguish 🙂

Hope this helps you create your local applications!