dependency management in go

24
Dependency Management in Go Poga

Upload: poga-po

Post on 28-Jan-2015

113 views

Category:

Technology


0 download

DESCRIPTION

Golang Taipei Gathering #2

TRANSCRIPT

Page 1: Dependency Management in Go

Dependency Management in Go

Poga

Page 2: Dependency Management in Go

A KickStarter

Page 3: Dependency Management in Go

Haunts

• Open Source• https://github.com/runningwild/haunts

• Written in Go• https://github.com/go-gl/gl

• Screwed by dependency hell

Page 4: Dependency Management in Go

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

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

Page 5: Dependency Management in Go

• $GOPATH/

• src/

• github.com/

• go-gl/

• gl/

• ...

• pkg/

• bin/

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

Page 6: Dependency Management in Go

import path

• 3 in 1

• remote repo url

• local package install path

• package name

Page 7: Dependency Management in Go

go get

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

Page 8: Dependency Management in Go

go get

git clone

go install

+=

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

Page 9: Dependency Management in Go

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

Page 10: Dependency Management in Go

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

Page 11: Dependency Management in Go

go 對你的 package 有所期待

Page 12: Dependency Management in Go

expectation of go

• green master policy

• always backward compatible

• remote repo url = local install path = package name

Page 13: Dependency Management in Go

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

Page 14: Dependency Management in Go

Haunts

• dependency renamed

• dependency becomes backward incompatible

• developer lost local installed version

• developer make local changes and didn’t push upstream

Page 15: Dependency Management in Go

Solutions

• Manage Dependencies by yourself

• ... or with some tools

• centralized package management

Page 16: Dependency Management in Go

DIY• $GOPATH/

• src/

• github.com/

• USER/

• PROJECT/

• ...

• vender/

• github.com/

• go-gl/• gl

• $GOPATH/

• src/

• github.com/

• USER/

• PROJECT/

• ...

• go-gl/

• gl/

• ...

Page 17: Dependency Management in Go

import "github.com/USER/PROJECT/vendor/github.com/go-gl/gl"

http://camlistore.org/ use this solutionrewrite import path with a python script

Page 18: Dependency Management in Go

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

Page 19: Dependency Management in Go

Tools

• Goven

• https://github.com/kr/goven

• copy local packages into project path

• and remove .git/

• rewrite import paths

Page 20: Dependency Management in Go

Tools

• Gopin

• https://github.com/laher/gopin

• download specified version

Page 21: Dependency Management in Go

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

Page 22: Dependency Management in Go

Centralized Package Management

• Go Nuts

• gonuts.io

• import “gonuts.io/vendor/nut”

• import “gonuts.io/vendor/nut/version”

• currently host 11 package only

Page 23: Dependency Management in Go

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

Page 24: Dependency Management in Go

Thank you

Q&A?