Slide 1

Slide 1 text

Dependency Management in Go Poga

Slide 2

Slide 2 text

A KickStarter

Slide 3

Slide 3 text

Haunts • Open Source • https://github.com/runningwild/haunts • Written in Go • https://github.com/go-gl/gl • Screwed by dependency hell

Slide 4

Slide 4 text

import "github.com/go-gl/gl" go get "github.com/go-gl/gl"

Slide 5

Slide 5 text

• $GOPATH/ • src/ • github.com/ • go-gl/ • gl/ • ... • pkg/ • bin/ import "github.com/go-gl/gl"

Slide 6

Slide 6 text

import path • 3 in 1 • remote repo url • local package install path • package name

Slide 7

Slide 7 text

go get go get "github.com/go-gl/gl"

Slide 8

Slide 8 text

go get git clone go install + = go get "github.com/go-gl/gl"

Slide 9

Slide 9 text

go get (the git clone part) • can’t specify version • looks for tag/branch name matching your go version • if no such exist, it goes for the most recent version/master branch • won’t update cloned repo by default • use -u

Slide 10

Slide 10 text

go get (the go install part) • build/install to $GOPATH • first path in $GOPATH if it contains multiple paths • weird behavior when package names conflict

Slide 11

Slide 11 text

go 對你的 package 有所期待

Slide 12

Slide 12 text

expectation of go • green master policy • always backward compatible • remote repo url = local install path = package name

Slide 13

Slide 13 text

BUT • People make mistakes • repos may change their name/location, or removed • same package, different import paths • Dependency Hell • what if your project depends on version A and a dependency needs version B? • different versions, same import paths

Slide 14

Slide 14 text

Haunts • dependency renamed • dependency becomes backward incompatible • developer lost local installed version • developer make local changes and didn’t push upstream

Slide 15

Slide 15 text

Solutions • Manage Dependencies by yourself • ... or with some tools • centralized package management

Slide 16

Slide 16 text

DIY • $GOPATH/ • src/ • github.com/ • USER/ • PROJECT/ • ... • vender/ • github.com/ • go-gl/ • gl • $GOPATH/ • src/ • github.com/ • USER/ • PROJECT/ • ... • go-gl/ • gl/ • ...

Slide 17

Slide 17 text

import "github.com/USER/PROJECT/vendor/github.com/go-gl/gl" http://camlistore.org/ use this solution rewrite import path with a python script

Slide 18

Slide 18 text

DIY Update • git submodule • http://git-scm.com/book/en/Git-Tools-Submodules • git subtree merge • http://git-scm.com/book/en/Git-Tools-Subtree-Merging

Slide 19

Slide 19 text

Tools • Goven • https://github.com/kr/goven • copy local packages into project path • and remove .git/ • rewrite import paths

Slide 20

Slide 20 text

Tools • Gopin • https://github.com/laher/gopin • download specified version

Slide 21

Slide 21 text

Tools • Rx • https://github.com/kylelemons/rx • track repos and their tags • update to a specified tag • automatically run tests for dependents • rollback if something is broken • save current versioning setup as a config • share this config with your team

Slide 22

Slide 22 text

Centralized Package Management • Go Nuts • gonuts.io • import “gonuts.io/vendor/nut” • import “gonuts.io/vendor/nut/version” • currently host 11 package only

Slide 23

Slide 23 text

My Conclusion • No perfect way (now) • use Camlistore way • vender 3rd-party dependencies • rewrite import path with makefile/scripts/goven • go/parser will be helpful

Slide 24

Slide 24 text

Thank you Q&A?