In the previous post we saw how to init modules, write one, publish it (locally with
replace directive) & use it on another Go project / module. This part we are going to publish the module to github and get rid of
replace way of aliasing.
Publishing to Github
Publshing to github is a no-brainer just init a git repo and push it to github. However the name of the repo does matters here since the consumers of our module would use that as the identifier.
Lets change the go.mod file on
localmod1. So that it points to a proper git repo than just a name.
module github.com/prassee/localmod1 go 1.12
now lets push it to github.
git init . git remote add origin firstname.lastname@example.org:prassee/localmod1.git ... git cm 'initial commit' git push origin master
Now the module is published to github. Lets proceed further to use it on other modules.
Using in other modules
This step does not require any coding but we just need to edit
go.mod file. Lets open
module usingmod1 replace github.com/prassee/localmod1 => ../localmod1 go 1.12 require github.com/prassee/localmod1 v0.0.0-00010101000000-00000000 0000 // indirect
in the above we just need to replace the 2nd line with the following and updated version should look like below.
module usingmod1 require github.com/prassee/localmod1 v1.0.2 go 1.12
now if we run
go mod tidy. we can see its downloading the artifact with the version as we desired.
> go mod tidy go: finding github.com/prassee/localmod1 v1.0.2 go: downloading github.com/prassee/localmod1 v1.0.2 go: extracting github.com/prassee/localmod1 v1.0.2
- Across this excercise we never used
go getcommand or had any vendor folder to manage our dependenceis.
- Modules were written outside the
Thats all folks .... I think I had covered the extent I know about Go Modules.
Claim your page on DEV before someone else does
Level up every day