Migrating to Go Modules

A presentation at Golang Poland in April 2020 in by Kat Cosgrove

Slide 1

Slide 1

A Recipe for Migrating to Go Modules

Slide 2

Slide 2

Kat Cosgrove ◂ ◂ ◂ ◂ ◂ IoT Engineer Developer Advocate Twitter: Dixie3Flatline Email: KatC@jfrog.com bit.ly/GoPolandJFrog 2

Slide 3

Slide 3

Modules are the Default …and migrating is easier than you think!

Slide 4

Slide 4

Mender.io ◂ Used for large-scale IoT deployments ◂ Build as a collection of microservices ◂ Varying version tags between services @Dixie3Flatline jfrog.com/shownotes @jfrog 4

Slide 5

Slide 5

Get a go.mod file go mod init ◂ ◂ ◂ ◂ ◂ Glide Godeps Govendor Dep … and more! v2+ ◂ ◂ ◂ ◂ Slightly more complex Increment major version Add to module path Causes some other issues to address `go mod init github.com/mendersoftware/deviceauth/v3’ @Dixie3Flatline jfrog.com/shownotes @jfrog 5

Slide 6

Slide 6

Update imports ◂ ◂ ◂ ◂ @Dixie3Flatline Build and test Both will likely fail Update import statements for new path May want to use a script for this in large projects jfrog.com/shownotes @jfrog 6

Slide 7

Slide 7

Module Versioning ◂ After go mod init or go mod tidy, check version numbers ◂ Some dependencies may cause problems here ◂ Untagged changes in satori/go.uuid broke Mender ◂ At this point, you should be able to build and run tests @Dixie3Flatline jfrog.com/shownotes @jfrog 7

Slide 8

Slide 8

Module Proxy ◂ ◂ ◂ ◂ ◂ JFrog GoCenter Immutable and persistent modules Much faster than cloning Consistent, secure, reproducible builds Vulnerability scanning built in export GOPROXY=https://gocenter.io @Dixie3Flatline jfrog.com/shownotes @jfrog 8

Slide 9

Slide 9

Static Analysis and Code Generators ◂ Some projects may need to handle additional issues with paths here ◂ Remember to look at your .proto and Dockerfiles @Dixie3Flatline jfrog.com/shownotes @jfrog 9

Slide 10

Slide 10

Testing Changes ◂ Go v1.13 made changes to testing ◂ Specifically, when flags are parsed ◂ Move flag.Parse() to main test function @Dixie3Flatline jfrog.com/shownotes @jfrog 10

Slide 11

Slide 11

Thanks! Any questions? You can find me at ◂ ◂ ◂ @Dixie3Flatline katc@jfrog.com bit.ly/GoPolandJFrog 11