Thanks for your advice! I will try your suggestion right away. I found that 
your approach some kind of similar to https://github.com/rogpeppe/gohack. 
But it seems we can't use that library since we have our internal tool to 
handle the importing of our shared libs. Thanks!

On Friday, May 8, 2020 at 5:51:54 PM UTC+7, Shulhan wrote:
>
>
>
> > On 8 May 2020, at 14.26, Reyhan Sofian Haqqi <[email protected] 
> <javascript:>> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0e109e09-23b4-4d45-8362-83b222e191c7%40googlegroups.com.

Reply via email to