On Fri, 31 Aug 2018 10:54:43 -0700 (PDT) Seth Hoenig <seth.a.hoe...@gmail.com> wrote:
> On Friday, August 31, 2018 at 12:22:28 PM UTC-5, Victor wrote: > > > > Hello everyone. I'm looking for best practices on how to setup your > > development environment using Go modules. > > > > Let assume a situation when you work on a project where you write a > > go package (call it Pkg) and an application (App) that uses that > > package Pkg and keep writing code in both. Using GOPATH, the > > process is pretty straightforward: you create your workspace, then > > you open $GOPATH/src/App project in your IDE and just continue > > editing .go files in both folders: $GOPATH/src/App and > > $GOPATH/src/Pkg where Pkg can be in a form " github.com/author/pkg" > > and that way in your App you can import it by the same > > "github.com/author/pkg" name and everything works since when you > > build App, it looks for that package in > > $GOPATH/src/github.com/author/pkg folder and always uses your > > latest changes. And since you have direct access to that folder in > > your IDE, you can continue editing Pkg while at the same time > > editing App. > > > > Now assume a situation where I want to get rid of GOPATH completely > > and start using modules. That way I'd put my App and Pkg folders in > > ~/Projects/App and ~/Projects/Pkg (since I don't have to put them > > in GOPATH any more). But then once App starts using go.mod file > > (assuming GO111MODULE is auto), it will be driven by > > "github.com/author/package" and store it in a local cache and not > > be using ~/Projects/Pkg where I make changes at the same time while > > working on ~/Projects/App. > > > > What would be the best practice to setup your development > > environment using Go modules? > > I am also stumbled on this issues, thanks for opening a topic on this. > > You'll want to add a replace directive to the go.mod file to > reference the copy of your library Pkg on disk, e.g. > > replace github.com/author/package => ../<wherever>/package > This method does not work if someone clone the application repository manually using VCS. I am not sure is this by design or an issue. For example, here is the application with "replace" directive [1], master ms 0 % git clone https://github.com/shuLhan/rescached-go Cloning into 'rescached-go'... remote: Counting objects: 277, done. remote: Compressing objects: 100% (158/158), done. remote: Total 277 (delta 141), reused 234 (delta 98), pack-reused 0 Receiving objects: 100% (277/277), 264.64 KiB | 544.00 KiB/s, done. Resolving deltas: 100% (141/141), done. 6:19 ~/tmp master ms 0 % cd rescached-go 6:19 ~/tmp/rescached-go master ms 0 % git reset --hard 47c04cb4542505173a0216edffb5b8388838966f HEAD is now at 47c04cb make: fix typo on sudo 6:28 ~/tmp/rescached-go master ms 0 % cat go.mod module github.com/shuLhan/rescached-go require github.com/shuLhan/share v0.0.0-20180827221555-192454617153 replace github.com/shuLhan/share => ../share When I run go build, it will report error about missing module, 6:28 ~/tmp/rescached-go master ms 0 % go build ./... go: parsing ../share/go.mod: open /home/ms/tmp/share/go.mod: no such file or directory go: error loading module requirements If I remove the "replace" directive, Go can build the package. 6:31 ~/tmp/rescached-go master ms 0 % cat go.mod module github.com/shuLhan/rescached-go require github.com/shuLhan/share v0.0.0-20180827221555-192454617153 6:31 ~/tmp/rescached-go master ms 0 % go build ./... I think my problem is thinking that "replace" directive is optional, as in, If "replace" path not exist, use module from cache, otherwise get the required package from remote into cache.-- Shulhan because the syntax use relative import, not absolute import path. [1] https://github.com/shuLhan/rescached-go/commit/47c04cb4542505173a0216edffb5b8388838966f -- 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. For more options, visit https://groups.google.com/d/optout.