Conan: A Go package manager

The source code

You can just clone the following example repository:

$ git clone

Or, alternatively, manually create the folder and copy the following files inside:

$ mkdir conan-goserver-example
$ cd conan-goserver-example
$ mkdir src
$ mkdir src/server

The files are:

src/server/main.go is a small http server that will answer “Hello world!” if we connect to it.

package main

import ""

func main() {
  m := martini.Classic()
  m.Get("/", func() string {
    return "Hello world!"

Declaring and installing dependencies

Create a conanfile.txt, with the following content:


 src, * -> ./deps/src

Our project requires a package, go-martini/1.0@, and we indicate that all src contents from all our requirements have to be copied to ./deps/src.

The package go-martini depends on go-inject, so Conan will handle automatically the go-inject dependency.

$ conan install .

This command will download our packages and will copy the contents in the ./deps/src folder.

Running our server

Just add the deps folder to GOPATH:

# Linux / Macos
$ export GOPATH=${GOPATH}:${PWD}/deps

# Windows

And run the server:

$ cd src/server
$ go run main.go

Open your browser and go to localhost:9300

Hello World!

Generating Go packages

Creating a Conan package for a Go library is very simple. In a Go project, you compile all the code from sources in the project itself, including all of its dependencies.

So we don’t need to take care of settings at all. Architecture, compiler, operating system, etc. are only relevant for pre-compiled binaries. Source code packages are settings agnostic.

Let’s take a look at the of the go inject library:
 import os
 from conans import ConanFile, tools

 class GoInjectConan(ConanFile):
     name = "go-inject"
     version = "1.0"
     license = "MIT"
     homepage = ""
     no_copy_source = True

     def source(self):

     def package(self):
                 dst=os.path.join("src", "", "codegangsta", "inject"),
                 src="inject-1.0-rc1", keep_path=True)

If you have read the Building a hello world package, the previous code may look quite simple to you.

We want to pack version 1.0 of the go inject library, so the version variable is “1.0”. In the source() method, we declare how to obtain the source code of the library, in this case just by downloading v1.0-rc1 tag. In the package() method, we are just copying all the sources to a folder named “src/”.

This way, we can keep importing the library in the same way:

import ""

We can export and upload the package to a remote and we are done:

$ conan create . # Or any other user/channel
$ conan upload go-inject/1.0@ --all

Now look at the go martini conanfile:
 import os
 from conans import ConanFile, tools

 class GoMartiniConan(ConanFile):
     name = "go-martini"
     version = "1.0"
     requires = "go-inject/1.0@"
     license = "MIT"
     homepage = ""
     no_copy_source = True

     def source(self):

     def package(self):
         self.copy(pattern="*", dst=os.path.join("src", "", "go-martini", "martini"),
                 src="martini-1.0", keep_path=True)

It is very similar. The only difference is the requires variable. It defines the go-inject/1.0@ library, as a requirement.

$ conan create . # Or any other user/channel
$ conan upload go-martini/1.0@ --all

Now we are able to use them easily and without the problems of versioning with github checkouts.