I am having real issues understanding what is going wrong.

When my project was self contained I thought I understood. 
Now I am trying to package it up I am in trouble. 
I had a project layout as follows (simplified)

webserver/config/config.go
webserver/template/template.go
webserver/servermain.go
webserver/go.mod

servermain.go is a sample project while I get the packages (config and 
template) right. It also serves as an example so I need to keep it in the 
project in git.

go.mod (contains)
  require github.com/mygit/webserver v0.0.0-20191018134507-cb1d694390ab // 
indirect
  replace github.com/mygit/webserver => ./

This all worked fine, I could update the code in config.go and it would be 
used in servermain.go without doing any downloads. 

I commited ALL of this and started a new project with the plan to use 
config and template package from above.

New project layout as follows (simplified)

ws2/server2.go
go.mod 
  require github.com/mygit/webserver v0.0.0-20191018134507-cb1d694390ab // 
indirect

I could not build this as it kept saying that the module was for 
servermain.go. I am a little vague hers as this was some time ago.

I gave up after a while and restructured the webserver as follows (adding 
example):

webserver/config/config.go
webserver/template/template.go
webserver/example/servermain.go
webserver/example/go.mod

>From the 'example' dir I ran 'go mod init' and 'go mod tidy'
No problem, it all ran and my go.mod file has:
require github.com/mygit/webserver v0.0.0-20191018134507-cb1d694390ab // 
indirect

I realised that config and template had been downloaded in to 
GOPATH/pkg/mod...
If I make changes to config locally they are NOT seen in 
example/servermain.go. 

So I set up the go.mod with a 'replace' but I cannot find a path that works.

replace github.com/stuartdd/webServerBase => ./
Fails with : 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

I have been trying various paths. They either reload GOPATH/pkg/mod (I 
delete this before each run) and ignote any changes I make to config.go or 
they fail to find the dependency.

What is the correct way to proceed while developing my servermain.go. 

What is the correct way to proceed when developing servers that import 
webserver (ws2/server2.go) and use config and template (without a replace 
in go.mod)

I am sure I am missing somthing minor. Could you please help.

Regards Stuart


On Monday, 23 September 2019 16:25:30 UTC+1, Stuart Davies wrote:
>
> 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.
>
>    - 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!). 
>    - Why do all imports start with github.com. Is that a requirement, 
>    what is the rational for this. 
>    - 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!* 
>
> 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
>

-- 
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/6903f217-c79d-4907-9767-636053ff60c2%40googlegroups.com.

Reply via email to