Importing from existing github project. Getting 'unknown revision' from mod tidy

Background

I am using GO 1.22.1, Linux Mint and VSCode as development tools. I was a Java dev for many years. I think GO is the best thing since sliced bread :slight_smile:

The GO language is easy to learn but package management is really confusing!

I have a large GO project that I developed more to learn go than any thing else. It is a simple web server for my raspberry pi.

I have the project in github and have been progressing well until now.

I have a main file goWebApp.go and 7 packages within the main directory. For the main app I use replace in the go.mod file so I can work locally.

Originally I did not have go.mod files in the sub ‘packages’ but had difficulty with some packages importing other packages.

The project is at GitHub - stuartdd/goWebApp: Web app written in go for raspberry pi home server. Please don’t be too critical, this has been my playground for may years.

-----goWebApp
    | config # Package - No internal deps
    ----| config.go
        | go.mod
    | controllers # Package depends on runCommand & config
    ----| controllers.go
        | go.mod
    | image # Package - No internal deps
    ----| image.go
        | go.mod
    | runCommand # Package - No internal deps
    ----| runCommand.go
        | go.mod
ETC.
    goWebApp.go
    go.mod # Listed below
module github.com/stuartdd/goWebApp
go 1.22.0

replace github.com/stuartdd/goWebApp/config => ./config
replace github.com/stuartdd/goWebApp/server => ./server
replace github.com/stuartdd/goWebApp/logging => ./logging
replace github.com/stuartdd/goWebApp/controllers => ./controllers
replace github.com/stuartdd/goWebApp/runCommand => ./runCommand
replace github.com/stuartdd/goWebApp/pictures => ./pictures
replace github.com/stuartdd/image => ./image
require (
    github.com/stuartdd/goWebApp/config v1.0.0
    github.com/stuartdd/goWebApp/logging v1.0.0
    github.com/stuartdd/goWebApp/pictures v1.0.0
    github.com/stuartdd/goWebApp/server v1.0.0
)
require (
    github.com/stuartdd/goWebApp/controllers v1.0.0 // indirect
    github.com/stuartdd/goWebApp/runCommand v1.0.0 // indirect
)

Note:

No go.sum file was created and I regularly build and run from command line.

I tried without go.mod files in the packages and was unable to import runCommand and config in to controllers.

I have created a v1.0.0 Release.

Current issue:

I am now creating a command line tool and want to reuse the code in the packages/modules from the goWebApp project but I have completely failed to import the code.

My new project go.mod is as follows:

module github.com/stuartdd/cmdline

go 1.22.0

require github.com/stuartdd/goWebApp v1.0.0

When I go mod tidy I get the following:

go: downloading github.com/stuartdd/goWebApp/config v0.0.0
go: downloading github.com/stuartdd/goWebApp/server v0.0.0
go: downloading github.com/stuartdd/goWebApp/pictures v0.0.0
go: downloading github.com/stuartdd/goWebApp/logging v0.0.0
go: github.com/stuartdd/cmdline imports
	github.com/stuartdd/goWebApp imports
	github.com/stuartdd/goWebApp/config: reading github.com/stuartdd/goWebApp/config/go.mod at revision config/v0.0.0: unknown revision config/v0.0.0
go: github.com/stuartdd/cmdline imports
	github.com/stuartdd/goWebApp imports
	github.com/stuartdd/goWebApp/logging: reading github.com/stuartdd/goWebApp/logging/go.mod at revision logging/v0.0.0: unknown revision logging/v0.0.0
go: github.com/stuartdd/cmdline imports
	github.com/stuartdd/goWebApp imports
	github.com/stuartdd/goWebApp/pictures: reading github.com/stuartdd/goWebApp/pictures/go.mod at revision pictures/v0.0.0: unknown revision pictures/v0.0.0
go: github.com/stuartdd/cmdline imports
	github.com/stuartdd/goWebApp imports
	github.com/stuartdd/goWebApp/server: reading github.com/stuartdd/goWebApp/server/go.mod at revision server/v0.0.0: unknown revision server/v0.0.0

I have cleaned cache and modcache with no impact.

If I change go.mod to require github.com/stuartdd/goWebApp v0.0.0 I get:

go: downloading github.com/stuartdd/goWebApp v0.0.0
go: github.com/stuartdd/cmdline imports
	github.com/stuartdd/goWebApp: reading github.com/stuartdd/goWebApp/go.mod at revision v0.0.0: unknown revision v0.0.0

I have tried for a couple of days, googling, reading, testing and repeat…

Questions

Can I include the modules/packages in goWebApp in another project or do I have to create new repositories for each module I want to reuse?

I believe I have structured goWebApp properly with github valid module names in go.mod files so where am I going wrong?

What is the best (and latest) way to structure a more complex project. A lot of the reading I have done is for old versions of GO and no longer valid!

Regards

Stuart