Hi.
I have been using GO for about a year and I love the language and ideas behind the language. I am also a Java developer for many years, I switched from Delphi to Java 1, the new and exciting language from Sun (a bit like GO is now from Google).
In Java we have Maven and Gradle (sorry Ant) to make dependency hell more manageable so I understand the need for modules in Go. I have just installed GO 1.13 and thought I would convert an existing 'pet' project to use modules. It did NOT go well!
What I need is a dummies guide to the GO module so I can build good, reliable, standards compliant GO applications.
I needs to explain the new terminology in the context of a module, like 'vendor'. Not just a one liner, I NEED to understand!
I know how to use Google but the quality of the articles I have read on this subject is minimal and just brushes the surface.
If I have a reasonably large and complex (pet) project with local packages in it. I like to split my project in to small units with 'namespaces' to keep it manageable. These are NOT reusable components until I decide they qualify and publish on Github.
We must have Modules and Repositories (like Maven Central) for the 'Enterprise' to manage dependencies but what about 'keep it simple' for the rest of us (and for that matter more mature enterprise developers like myself).
Please help me get this understood. This is the sort of thing that can raise a language above the rest and I would really like that to happen. Go is brilliant…
Regards
Stuart
If I have a reasonably large and complex (pet) project with local packages in it. I like to split my project in to small units with 'namespaces' to keep it manageable. These are NOT reusable components until I decide they qualify and publish on Github.
Why MUST I import them as if they are from github and then 'replace' them, and if I don’t 'MUST' then you have failed to explain this feature to me!
My local packages are part of my application. They are, I agree still 'dependencies' but they are not 'DEPENDENCIES' that I need (or even want) to import from a repository. They are part of my project.
What if I do not want to host my project on a GIT repo (Shock horror!).
How does a 'import' resolve its 'reference'.
Should I add the go.mod and go.sum files to my repository or should the developer who cloned my project have to do a go mod init (bummer!).
Can someone please explain, properly!
webserver/config/config.go
webserver/template/template.go
webserver/servermain.go
webserver/go.mod
require github.com/mygit/webserver v0.0.0-20191018134507-cb1d694390ab // indirect
replace github.com/mygit/webserver => ./
require github.com/mygit/webserver v0.0.0-20191018134507-cb1d694390ab // indirect
webserver/config/config.go
webserver/template/template.go
webserver/example/servermain.go
webserver/example/go.mod
require github.com/mygit/webserver v0.0.0-20191018134507-cb1d694390ab // indirect
replace github.com/mygit/webserver => ./
build command-line-arguments: cannot load github.com/mygit/webserver/config: module github.com/mygit/webserver@latest (v0.0.0-20191018134507-cb1d694390ab) found, but does not contain package github.com/mygit/webserver/config
── webserver
├── config
│ ├── config.go
├── example
│ ├── go.mod
│ ├── go.sum
│ ├── webserver.go
├── exec
│ ├── exec.go
│ └── exec_test.go
module webserver.go
go 1.13
require github.com/mygit/webserver v0.0.0-20191018134507-cb1d694390ab // indirect
replace github.com/mygit/webserver => ./
module github.com/mygit/webserver
go 1.13
replace github.com/mygit/webserver => ../
go mod init <name>
── webserverbase
├── config
│ ├── config.go
├── example
│ ├── go.mod // Mod file 1
│ ├── go.sum
│ ├── webserver.go
├── exec
│ ├── exec.go
│ └── exec_test.
go
├── go.mod // Mod file 2
├── go.sum
Ok this is my current understanding. Please correct me if I am wrong.
1) The main purpose of a go.mod file is to indicate where the dependencies are and their version number.
2) In my small project the 'module' is 'where the go.mod file is' (root of webserver).
3) A module contains packages in sub dirs (these are what we import).
a) If it has no packages in sub dirs is it still a module?
b) Import dependencies between packages in a module must use the full module path and the package name
c) There should be no main() in a module
4) The directory 'example' is a module (it has a go.mod) file.
a) It has NO packages of it's own.
b) It has a dependency on the 'webserver' module which must have a go.mod file (as it does).
c) The purpose of the 'example' mod file is to locate the module dependencies (not the packages)
d) Strictly speaking this is NOT a module (nothing will depend on it) so I should either move it outside the module or get go mod to ignore it by prefixing with '_'
e) It is where the main() is.
f) Is there any reason it could not be a module and be a dependent of another module?
Modules are normally stored in git (or equivilant) but even if they are not they need a module name that includes the git path and a go.mod file.
My 'webserver' go.mod file was created with the name:
github.com/mygit/webserver
My 'example' was created with the name:
github.com/mygit/webserver/example
I have a sneeking feeling that if outside of 'webserver' it would be:
github.com/mygit/example
Could it be:
github.com/mygit/webserver/example
Or if renamed:
github.com/mygit/webserver/_example
I am really not sure what the correct name is here. If not a dependency, does it matter?
Now for 'replace' this is where I get a bit vague.
Replace, changes a module's dependency path. Either changing the version number or the actual modules full path. E.g. => github.com/someothergit/webserver.
Replace can change a modules path to a local directory path.
a) A local path of ./ indicates that the dependency (module) is in the same 'module' (as with example currently)
b) A Local path of ../ indicates that the dependency (module) is one level up.Is this in the same module or one levelup from the go.mod file?
c) A Local path of ../foo indicates that the dependency (module) is one level up in the directory called 'foo'.In my case if 'foo' contained 'webserver' would the path be:
../foo/webserver
Or
../foo
Are there any diagnostics for dependency resolution.
Is there anyway of logging what the actual resultant 'replace' finds (or not). It seems to fallback, ignoring the replace, if it cannot be found. This would be really informative.
On Oct 25, 2019, at 9:14 AM, Stuart Davies <sdd.d...@gmail.com> wrote:
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a9c56752-3660-4c6b-bd9e-36887c7ff417%40googlegroups.com.