After long search still trouble with packages and architecture


I am trying to establish an architecture with go as suggested here (others are quite similiar):

So I have my_project_folder/cmd/app/main.go and I run my application from the main folder with go run cmd/app. So far so good.

Now I want to break my code in several pieces for internal usage, so I create:

  • my_project_folder/internal/pkg/libone containing several go - files, all of them are declared to be in package libone.
  • Equivalently I also create my_project_folder/internal/pkg/libtwo also containing some go - files and declared as libtwo.

So I end up with the following architecture / structure (excerpt):

  • my_project_folder/cmd/app/main.go
  • my_project_folder/internal/pkg/libone/*.go
  • my_project_folder/internal/pkg/libtwo/*.go

The question is how would I import my two libraries in my main.go?

One working option is to use relative paths (../..). But I already read that this is bad practice in the go-universe. Another, the better, option would be to use “remote paths”, right?

So even though I do not use github, I try to change the import in my main.go to:
But this crashes… Is this because I have no mods.go file? Or do I still have to set my GOPATH? (I thought this is not needed anymore?)

Is there an explicit documentation on how remote paths are resolved? And how can I avoid that if somebody enters git get no unwanted repository from github is pulled because I just used a fake name?

Thanks in advance and Sorry for the big confusion… I would not have asked If I were successful in searching :frowning:

This board really helps :slight_smile: I just made another try creating a go module in my main directory… Thereafter my IDE took over and corrected my imports :slight_smile: Now it is working like a charm :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.