Stream Is Deprecating Virtual Go – It’s Time to Move to Go Modules
Tags: go, modules, programming, announcement
Published: 2020-01-16 11:14:34

## TL;DR

[Stream](https://getstream.io/) released [vg](https://github.com/GetStream/vg) almost three years ago, and since its inception, [Go](https://golang.org/) has improved quite a bit in regards to its dependency management. Since Go has come so far, we’re now advocating that the community use native [Go modules](https://blog.golang.org/using-go-modules) rather than vg.

## The Gist

[Stream](https://getstream.io) provides an API as a service to build highly scalable feeds and white-label chat for any application or messaging service. In the beginning days of Stream, the entire infrastructure utilized Python on the backend; however, the amount of throughput demanded by Stream's customers, in addition to the growing size of the development team, made Python inadequate for continued use. With that, the team decided to switch to a more performant programming language – Go.

We have already written about our decision-making process a couple of years on [our blog](https://getstream.io/blog/switched-python-go/), there were many things we liked about Go at that time. Unfortunately, dependency management was not one of them – there were no lockfiles, no clear way to version dependencies, etc.

For this reason, we wrote a small library called "virtualgo" that wrapped [dep](https://github.com/golang/dep) and made it dead simple for developers to work on several Go projects at the same time without dependency clashing.

> _**Note**: Everything that motivated us 3 years ago does not apply anymore to dependency management in Go. Modules have solved all these problems and added additional functionality as well such as enforcing [semver](https://semver.org/), immutability and checksum database, etc._

We were very excited about Go modules and tried them as soon as possible ([Go 1.11](https://blog.golang.org/go1.11)). Sadly we had to postpone using them as many libraries did not support them at all; in July of 2019, all libraries we needed had support for modules, and we started migrating projects over.

Migrating to Go modules is incredibly easy; in our case, because we used vg and dep, we could use go mod itself to migrate the dependency manifests. Surprisingly that was pretty much all we had to do.

A few items to expand:

* [Cgo](https://golang.org/cmd/cgo/) isn’t Go and very problematic. It’s almost always a good idea to stay away from it because most of the guarantees of Go, for example, in terms of portability, don’t exist.
* We have used _tools package pattern_ to track the exact version of our necessary tools such as stringer, protocol buffers, etc. By this, there is no divergence between developer environments. This package is also guarded by _tools_ build flag, which doesn’t add any overhead into the build speed or output.
* Thanks to modules we were able to drop some build optimizations that made our build pretty complex.
* We’re using sentry for error reporting, which can generate context snippets whenever an error occurs, we have used vendor mod to generate these snippets for 3rd party dependencies, too.

## Summary

1. Two years ago we switched from [Python to Go](https://getstream.io/blog/switched-python-go/) 
2. We did not find a solution to dependency management that we liked (we tried Glide, dep, vendor, etc.)
3. We built [virtualgo](https://github.com/GetStream/vg) and open-sourced it ❤️
4. Virtualgo solved the necessary need for Go dependency management and was/is used by many Go developers; (1.1k stars as of writing this on GitHub)
    1. Virtualgo solved these problems
        1. GOPATH based solution
        2. No vendoring
        3. No shared dependencies between projects
        4. Simplify integration with Dep 
5. Go added support for modules in `1.11`
6. Initial support for modules was experimental; however, it, later on, became stable, but many libraries broke in the process
    2. Go generate did not work; no stringer
7. Go modules are now very well supported; at this point any standard and well-maintained library supports it 
8. Why modules are excellent and better than vg
    3. Blessed by the community (one of dep’s author was upset about this 🔥)
    4. Lockfile (`go.sum`)
    5. Fast
    6. Supports proxies out of the box
    7. Private Github repo; no problem
    8. Put any Go project anywhere you want
    9. No more “github.com” in your import path
9. What’s next
    10. vg will stay around as long as GitHub will allow it
    11. We are not using it anymore; other devs might so if needed we are happy to add a new maintainer and review / merge PRs
    12. we are going to add a disclaimer + link to this article on the Github readme
    13. how to migrate from vg to modules
        5. First, have a look at Go official docs to get an idea about [modules]([https://github.com/golang/go/wiki/Modules](https://github.com/golang/go/wiki/Modules))
        6. vg wraps dep; migration is super simple (we did that, and it was painless)