On Tue, 6 Apr 2021 19:39:00 -0400
rob <drrob...@fastmail.com> wrote:

>  > This example is on Win10 using go 1.16.3
> 
> Now I've created a directory tree outside of ~/go/src.  I'm using ~
> to mean %userprofile%, as this is win10
> 
> ~/gcode/rpng/rpng.go
> 
> ~/gcode/tokenize/tokenize.go
> 
> ~/gcode/hpcalc2/hpcalc2.go
> 
> And I updated my import statement to be "gcode/hpcalc2", etc.
> 
> Now I can use
> 
>       go run gcode/rpng/rpng.go
> 
> And I set GOBIN=c:\Users\rob\gcode
> 
>      go install gcode/rpng/rpng.go
> 
> and it installs to GOBIN.
> 
> At least it's working for me mostly the way it was before.  I just
> had to abandon my ~/go directory
> 
> Thanks for answering
> 
> Rob
> 

Hi Rob, it's good that you got it working, but I feel you're struggling
with modules inferred from your past emails due a confusion between a
module namespace and the file system, your package import paths and go
commands are relative to a *module* and not a directory, your current
module namespace is detected similarly as a git repository is, that is,
traverse current working directory up until a go.mod is found (or .git
for git), and then if a module is found, you import packages or use the
go commands in the format of *module_name*/folder/..., not file system
paths, what go cares as a namespace is the module name, not
absolute/relative file system paths.

For example, suppose our current working directory is "~/gcode/" and it
has a go.mod named¹ "foo", note that the folder is named gcode but the
module is "foo", you would install the "rpng" package inside this
module namespace "foo" with:
$ go install foo/rpng

you can refer file path relatives alike as well:
$ go install ./rpng # OK
$ go install rpng # invalid, would fail with the same not found message

you can think as dot expanding to "foo", not the file system gcode
folder, to make clear that it's not about file system paths, changing
our current working directory to "tokenize", we still can mention "rpng"
relative to the module, not the file system:
$ cd ~/gcode/tokenize
$ go install foo/rpng
$ go install ../rpng # valid as well

I'm not sure if this helps you or causes even more confusions, if so
sorry.

BR.

--wagner

[1] the module name is usually a domain, but not necessarily, refer to
https://pkg.go.dev/golang.org/x/mod/module#CheckPath for detailed
description.

-- 
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/20210407112419.1e5e0132%40pampas.

Reply via email to