Migrating to modules

103 views
Skip to first unread message

l...@pinkfroot.com

unread,
Jun 27, 2019, 1:47:20 AM6/27/19
to golang-nuts
All of my projects at the moment are living under GOPATH/src/me/projectName.

Is it possible to migrate to using GoModules and pin (for now) the packages at the versions stored in my GOPATH/src.  I am thinking that way the migration to GOMODULES will produce a build no different to the build using GOPATH/src for all the packages.

From that point on I then know I am at a good place and can look to upgrade packages for that migrated project.

Is this possible and if so how?  I am using Go1.12 now but happy if this is in 1.13

Thanks!


Kasun Vithanage

unread,
Jun 27, 2019, 1:59:53 AM6/27/19
to golang-nuts
Yes you can easily migrate. Go will automatically generate mod files based on your projects.

Just go into the project and run
GO111MODULE=on go mod init <YOUR_PROJECT_NAME>
and everything will be ok.

If you are storing your projects in a VCS like Github just make sure you put repo name as the PROJECT NAME

Ex: 
GO111MODULE=on go mod init github.com/username/projectname

For more

Regards.
Kasun

les...@gmail.com

unread,
Jun 27, 2019, 3:29:25 AM6/27/19
to golang-nuts
Thanks Kasun,

One thing that is not 100% clear is what packages and versions (more importantly) get set when you migrate to using modules.

Is it the current version on the local disks?

Lee

Kasun Vithanage

unread,
Jun 27, 2019, 3:51:03 AM6/27/19
to golang-nuts
According to this it will try to create an equivalent build. It will not break your code
Reply all
Reply to author
Forward
0 new messages