> On 8 May 2020, at 14.26, Reyhan Sofian Haqqi <computecoho...@gmail.com> wrote:
> 
> The question is why you can't have any version inside the shared libs? How do 
> you shared the libs locally? 
> 
> Because we use monorepo. Maybe git tag works since it's also pointing to a 
> commit hash? but does it works if we use `replace` directive on go.mod file?

IMO, you should use replace directive only for VCS to VCS. For example, if you 
have a fork of module X, and you want to use your fork instead of upstream you 
can set in go.mod with,

  replace remote/upstream/X => my/fork/X

Setting the right hand side of "replace" directive to filesystem path will make 
the go tools to use the code in that directory without version. See the wiki 
page on Modules for more information [1].

> 
> If the replace directive use local path then I am afraid it will use the 
> latest pseudo version.
> 
> Yes. This what we use for now. Do you have any suggestions about this?
> 

Treat your shared library as module or in another terms, as a normal project, 
commit, push changes, or add versioning into it.

Here is the steps that I usually do,

*  Doing development on main module, uncomment the replace directive _only_ if 
you need to make some changes on your local shared lib.

  replace your/share/lib => ../lib

*  After the changes, and the test has passed, comment the replace directive 
back.

  // replace your/share/lib => ../lib

*  Commit the changes in your shared library and push it to the remote 
repository

*  Back to main module, run

  $ go get your/share/lib
  $ go mod tidy

* You should get the latest pseudo-version. Commit it and push to remote 
repository.

In this way, all others developers will get and use the same version of shared 
lib.  One of common mistake is to forgot to comment the "replace" directive 
back.

[1] 
https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/A915FDC4-3C0B-439C-A9C3-93E913CD1052%40gmail.com.

Reply via email to