Re:[go-nuts] Re: How go.work knows which module refers to which folder

2022-04-06 Thread 'Jack Li' via golang-nuts
Thanks.


I think I may get it.


If there's go.work, the `import example.com/module` will try those local 
directories in go.work first. If not found, it will try online repositories. 
And module names like this `example.com/module`, `github.com/golang/glog`, etc. 
are unique, so there will be no ambiguous. Am I thinking right?





--Original--
From:   
 "thepud...@gmail.com"  
  
From the Go workspaces reference (https://go.dev/ref/mod#workspaces) :

 A 'use' adds a module on disk to the set of main modules in a workspace. 
Its argument is a relative path to the directory containing the module’s go.mod 
file. A 'use' directive does not add modules contained in subdirectories of its 
argument directory. Those modules may be added by the directory containing 
their go.mod file in separate 'use' directives.

Hope that helps, and sorry if that does not address your question.

Regards,
thepudds


On Wednesday, April 6, 2022 at 9:43:12 AM UTC-4 Jack Li wrote:

Hi group,


In the go.mod replace way, there’s a one-to-one mapping relationship, for 
example, the module example.com/hello is mapped to folder …/hello


```
$ go mod edit -replace example.com/hello=../hello
$ view go.mod
replace example.com/hello = ../hello
$
```


Now with the go.work way. If I've got three repos or modules like this:


```
module main
go 1.18
require example1.com/hello v1.0.0
require example2.com/hello v1.0.0
require example3.com/hello v1.0.0
```


How can go.work know which module above, refers to ./hello ?


```
go.work:
use ./hello
```


Thanks


 

 -- 
 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/7c90c2a4-7a81-4e16-b1fe-8ddd19b72f12n%40googlegroups.com.

-- 
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/tencent_92E509C4160EBDE79705E7628818074DAA0A%40qq.com.


[go-nuts] Re: How go.work knows which module refers to which folder

2022-04-06 Thread thepud...@gmail.com
Hi there,

I might be misunderstanding your question, but a 'use' directive in a 
go.work file points to a directory. 

In your example, there would not be any ambiguity -- 'use ./hello' in a 
go.work file would refer to whatever module you have located in the 'hello' 
directory in your local filesystem immediately below the go.work file.

>From the Go workspaces reference (https://go.dev/ref/mod#workspaces) :

> A 'use' adds a module on disk to the set of main modules in a workspace. 
Its argument is a relative path to the directory containing the module’s 
go.mod file. A 'use' directive does not add modules contained in 
subdirectories of its argument directory. Those modules may be added by the 
directory containing their go.mod file in separate 'use' directives.

Hope that helps, and sorry if that does not address your question.

Regards,
thepudds

On Wednesday, April 6, 2022 at 9:43:12 AM UTC-4 Jack Li wrote:

> Hi group,
>
> In the go.mod replace way, there’s a one-to-one mapping relationship, for 
> example, the module example.com/hello is mapped to folder …/hello
>
> ```
> $ go mod edit -replace example.com/hello=../hello
> $ view go.mod
> replace example.com/hello => ../hello 
> $
> ```
>
> Now with the go.work way. If I've got three repos or modules like this:
>
> ```
> module main
> go 1.18
> require example1.com/hello v1.0.0
> require example2.com/hello v1.0.0
> require example3.com/hello v1.0.0
> ```
>
> How can go.work know which module above, refers to ./hello ?
>
> ```
> go.work:
> use ./hello
> ```
>
> Thanks
>

-- 
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/7c90c2a4-7a81-4e16-b1fe-8ddd19b72f12n%40googlegroups.com.