#struggling with modules

15 messages · Page 1 of 1 (latest)

small tulip
#

Supposed I have a repo like so:

application/
  core/
    go.mod -> github.com/me/application/core
    <source-files>
  cli/
    go.mod -> github.com/me/application/cli
    <source-files>
  README

How would I go about importing code from core if I'm in cli? Importing as github.com/me/application/core has not been working. What am I missing?

urban remnant
#

your structure is kind of confusing.
you usually have to put one go.mod at the root of the repository.

small tulip
#

so there has to be a go.mod file at the root even if there is not really a me/application module?

#

I'm really just using application as a "namespace" for my modules.

#

Is that an antipattern?

mental drift
#

In the root of the project you should have your go main.go and go.mod.

#

Then you can have your packages in sub directories.

#

There's a post about it. One sec.

#

It doesn't need to be called main.go for what it's worth, just shorthand.

#

You can call it mysupersweetapp.go, as long as the package is main, and it's in the root folder your project.

urban remnant
#

there is a difference between a module and a package btw, if you're confused about it.
since you want to make the "core" an importable package, it doesn't really make sense to put go.mod inside

small tulip
#

Got it. Thanks for the advice

small tulip
glad wyvern
#

Can I know the exact error your are facing?