I would work through https://golang.org/doc/code.html
- Amnon On Friday, 22 May 2020 12:59:03 UTC+1, lj0...@gmail.com wrote: > > It looks like I am not only one to struggle with (new?) go modules. > I still consider me as novice to GO but the major problem is as usual, the > focus. > > 1. Modules are complicated to understand > 2. Lack of examples (of real use, not just POC) > 3. Focus on extra (scale up) details (that are surely important) and none > of focus on basic things (which are essentially more important as they make > things working and not working) > > I have spent several days in attempt to make a working module and I > failed. > I learned a lot of things on the way but still did not manage to make a > working example. > The working example in my understanding shall be given as: > > Variant 1: Making executable > > 1. how the main (executable) uses the module (import and function call, > how to avoid function name conflicts?) > 2. how to build a module that 1.(main program uses) > 3. how and where to compile and what and what compilation output to expect > > Variant 2: Making library > > In a way a module is a library but, one may want to make his own library > that will be used in his project and within that library use his custom > modules, so we go the same > > 1. how library modules uses the custom module (import and function call > and how to avoid function name conflicts from different modules? > and > 2. which shall be the same as for Variant 1. How really to make a working > module. > 3. which shall be the same as for Variant 1. how and where to compile and > what and what compilation output to expect > > this is more a feedback on what conceptually I am struggling with go and > modules > > ------- > > On the other note the relation between gopath and modules. Currently (I am > trying to use go 1.14) I understand that there is a method of 'gopath' > where go will seek for libraries. This goes to compilation part. > > Say have i have a custom module site/name/module (literally) > > what i put in package part? what would be relation between main and > others. In others - is there package site/name ? > where to put sources so go finds them? (while compilation gopath method > suggests where to put sources - it is a help but is this correct way of > doing things? > how to compile these sources so it is explained which modules are used > (and from where)? > if I just compile a module - what do I get ? If I get some sort of an > object - where to look for it? How it is called? How do I reference it from > the source. > > For example in my experimental trials I get (a hello world executable > trying to call function defined in a module) > > I am getting error: 'site/name/module' imported and not used > of course since module is not found > I also get error: undefined: Hello > which is a function I try to call. > > Hope all of these make sense, and possibly someone wrote somewhere > something of these but so far I did not find it. And I LIKE reading > documentation, but documentation is just partially helpful. > > Thanks > > > > > > > > > > > > On Tuesday, May 5, 2020 at 1:28:55 PM UTC+2, Amnon Baron Cohen wrote: >> >> Interesting. At first sight this should work. >> >> You definitely don't need a go.mod file in ~HOME/src/myrepo/cmd/cmd1 >> >> Which go version are you running? >> >> What is your $GOPATH set to? >> >> What output does cd ~HOME/src/myrepo; go build give? >> >> The usual convention is to push the code in a VCS such as github and use >> the vcs path as an argument to go mod init >> >> e.g. >> go mod init github.com/myuser/myrepo >> >> - Amnon >> >> On Monday, 4 May 2020 14:59:22 UTC+1, web user wrote: >>> >>> I have a personal project using GOPATH >>> >>> But recently, I wanted to use go-redis for a project and v7 forces you >>> to use go mod. So I figured, I'd migrate the account over to go mod. But >>> I'm stuck. >>> >>> >>> My directory structure is: >>> >>> ~HOME/src/myrepo >>> ~HOME/src/myrepo/cmd/cmd1 >>> ~HOME/src/myrepo/commong >>> ~HOME/src/github >>> >>> So I did the following command: cd ~HOME/src/myrepo; go mod init >>> ~HOME/src/myrepo >>> >>> when I run the command go build ~HOME/src/myrepo/cmd/cmd1/... >>> >>> It does not update the go.mod in the directory ~HOME/src/myrepo? Do I >>> need a go.mod in ~HOME/src/myrepo/cmd/cmd1 >>> >>> >>> -- 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/592b93a4-1508-49db-b8f1-a82237ba88ff%40googlegroups.com.