Skip to content

Latest commit

 

History

History
313 lines (247 loc) · 10.9 KB

README.md

File metadata and controls

313 lines (247 loc) · 10.9 KB

Intro

Buffalo is a popular Go web development eco-system, "designed to make the life of a Go web developer easier." Before switching to Go modules, Buffalo used dep for dependency management.

This guide looks at the steps that were required to migrate from dep to Go modules and is based on a PR Russ Cox opened against the Buffalo project. Note the go tool understands a number of different dependency management formats including Glide and Godeps; the steps for migrating from these will be similar.

The results of this migration can be found at https://github.com/go-modules-by-example/buffalo.

Getting started

We will use known commits of Buffalo and dep so the guide remains reproducible:

$ buffaloCommit=354657dfd81584bb82b8b6dff9bb9f6ab22712a8
$ depCommit=5025d70ef6f298075c16c835a78924f2edd37502

The migration

Let's perform this migration in a clean GOPATH (remember, Buffalo is not yet a module for the purposes of this guide). We also update our PATH to make it easier to run dep.

$ export GOPATH=$(mktemp -d)
$ export PATH=$GOPATH/bin:$PATH
$ cd $GOPATH

Get dep and ensure we have our desired commit installed:

$ go get -u github.com/golang/dep/cmd/dep
$ cd src/github.com/golang/dep/cmd/dep
$ git checkout $depCommit
HEAD is now at 5025d70e... CHANGELOG: prepare for 0.5.2 release
$ go install

Get Buffalo at the desired commit:

$ cd $GOPATH
$ go get -tags sqlite github.com/gobuffalo/buffalo
$ cd src/github.com/gobuffalo/buffalo
$ git checkout $buffaloCommit
HEAD is now at 354657d... Updated SHOULDERS.md
$ go get .

Verify that Buffalo's tests pass by using dep ensure and then running tests.

$ dep ensure
$ go test -tags sqlite ./...
ok  	github.com/gobuffalo/buffalo	0.198s
ok  	github.com/gobuffalo/buffalo/binding	0.024s
?   	github.com/gobuffalo/buffalo/buffalo	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd/build	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd/destroy	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd/generate	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd/updater	[no test files]
ok  	github.com/gobuffalo/buffalo/generators	0.016s
ok  	github.com/gobuffalo/buffalo/generators/action	0.024s [no tests to run]
?   	github.com/gobuffalo/buffalo/generators/assets	[no test files]
?   	github.com/gobuffalo/buffalo/generators/assets/standard	[no test files]
?   	github.com/gobuffalo/buffalo/generators/assets/webpack	[no test files]
?   	github.com/gobuffalo/buffalo/generators/docker	[no test files]
?   	github.com/gobuffalo/buffalo/generators/grift	[no test files]
?   	github.com/gobuffalo/buffalo/generators/mail	[no test files]
ok  	github.com/gobuffalo/buffalo/generators/newapp	1.946s
?   	github.com/gobuffalo/buffalo/generators/refresh	[no test files]
ok  	github.com/gobuffalo/buffalo/generators/resource	0.014s
?   	github.com/gobuffalo/buffalo/generators/soda	[no test files]
?   	github.com/gobuffalo/buffalo/grifts	[no test files]
ok  	github.com/gobuffalo/buffalo/mail	0.061s
?   	github.com/gobuffalo/buffalo/meta	[no test files]
ok  	github.com/gobuffalo/buffalo/middleware	0.141s
ok  	github.com/gobuffalo/buffalo/middleware/basicauth	0.028s
ok  	github.com/gobuffalo/buffalo/middleware/csrf	0.046s
ok  	github.com/gobuffalo/buffalo/middleware/i18n	0.032s
?   	github.com/gobuffalo/buffalo/middleware/ssl	[no test files]
ok  	github.com/gobuffalo/buffalo/middleware/tokenauth	0.038s
?   	github.com/gobuffalo/buffalo/plugins	[no test files]
ok  	github.com/gobuffalo/buffalo/render	0.025s
ok  	github.com/gobuffalo/buffalo/worker	0.015s

Up until this point we have been working in "GOPATH mode". Because we are working inside GOPATH we need to explicitly switch to "module-aware mode" to perform any module operations:

$ export GO111MODULE=on

Initialise our module (see the wiki for more details):

$ go mod init
go: creating new go.mod: module github.com/gobuffalo/buffalo
go: copying requirements from Gopkg.lock

Tidy for good measure:

$ go mod tidy
go: finding github.com/gobuffalo/flect v0.1.3
go: finding github.com/ajg/form v1.5.1
go: finding github.com/markbates/safe v1.0.1
go: finding github.com/mitchellh/go-homedir v1.1.0
go: finding github.com/gobuffalo/uuid v2.0.5+incompatible
go: finding github.com/gobuffalo/github_flavored_markdown v1.0.7
go: finding github.com/gobuffalo/events v1.3.1
...

Verify that our go.mod has been populated with dependencies:

$ cat go.mod
module github.com/gobuffalo/buffalo

go 1.12

require (
	github.com/ajg/form v1.5.1 // indirect
	github.com/dgrijalva/jwt-go v3.2.0+incompatible
...

Run tests to confirm that behaviour hasn't changed:

$ go test -tags sqlite ./...
ok  	github.com/gobuffalo/buffalo	0.188s
ok  	github.com/gobuffalo/buffalo/binding	0.016s
?   	github.com/gobuffalo/buffalo/buffalo	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd/build	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd/destroy	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd/generate	[no test files]
?   	github.com/gobuffalo/buffalo/buffalo/cmd/updater	[no test files]
ok  	github.com/gobuffalo/buffalo/generators	0.008s
ok  	github.com/gobuffalo/buffalo/generators/action	0.031s [no tests to run]
?   	github.com/gobuffalo/buffalo/generators/assets	[no test files]
?   	github.com/gobuffalo/buffalo/generators/assets/standard	[no test files]
?   	github.com/gobuffalo/buffalo/generators/assets/webpack	[no test files]
?   	github.com/gobuffalo/buffalo/generators/docker	[no test files]
?   	github.com/gobuffalo/buffalo/generators/grift	[no test files]
?   	github.com/gobuffalo/buffalo/generators/mail	[no test files]
ok  	github.com/gobuffalo/buffalo/generators/newapp	2.191s
?   	github.com/gobuffalo/buffalo/generators/refresh	[no test files]
ok  	github.com/gobuffalo/buffalo/generators/resource	0.026s
?   	github.com/gobuffalo/buffalo/generators/soda	[no test files]
?   	github.com/gobuffalo/buffalo/grifts	[no test files]
ok  	github.com/gobuffalo/buffalo/mail	0.035s
?   	github.com/gobuffalo/buffalo/meta	[no test files]
ok  	github.com/gobuffalo/buffalo/middleware	0.118s
ok  	github.com/gobuffalo/buffalo/middleware/basicauth	0.030s
ok  	github.com/gobuffalo/buffalo/middleware/csrf	0.025s
ok  	github.com/gobuffalo/buffalo/middleware/i18n	0.032s
?   	github.com/gobuffalo/buffalo/middleware/ssl	[no test files]
ok  	github.com/gobuffalo/buffalo/middleware/tokenauth	0.048s
?   	github.com/gobuffalo/buffalo/plugins	[no test files]
ok  	github.com/gobuffalo/buffalo/render	0.032s
ok  	github.com/gobuffalo/buffalo/worker	0.015s

Remove the now redundant vendor directory and Gopkg.toml, commit and push:

$ rm -rf vendor Gopkg.toml
$ git remote add go-modules-by-example https://github.com/go-modules-by-example/buffalo
$ git checkout -q -b migrate_buffalo
$ git add go.mod go.sum
$ git commit -am 'Convert to a Go module'
[migrate_buffalo 9bec060] Convert to a Go module
 14 files changed, 799 insertions(+), 5648 deletions(-)
 delete mode 100644 Gopkg.toml
 create mode 100644 go.mod
 create mode 100644 go.sum
 delete mode 100644 vendor/github.com/russross/blackfriday/.gitignore
 delete mode 100644 vendor/github.com/russross/blackfriday/.travis.yml
 delete mode 100644 vendor/github.com/russross/blackfriday/LICENSE.txt
 delete mode 100644 vendor/github.com/russross/blackfriday/README.md
 delete mode 100644 vendor/github.com/russross/blackfriday/block.go
 delete mode 100644 vendor/github.com/russross/blackfriday/doc.go
 delete mode 100644 vendor/github.com/russross/blackfriday/html.go
 delete mode 100644 vendor/github.com/russross/blackfriday/inline.go
 delete mode 100644 vendor/github.com/russross/blackfriday/latex.go
 delete mode 100644 vendor/github.com/russross/blackfriday/markdown.go
 delete mode 100644 vendor/github.com/russross/blackfriday/smartypants.go
$ git push -q go-modules-by-example

If you want to retain vendor, see "Using modules to manage vendor" for more details.

Version details

go version go1.12.5 linux/amd64