3

I have a public kit repo which I pushed v1.0.3 on and has the following structure

go
-database
--database.go
--go.mod
--go.sum

And I require it with

require github.com/michael-ottink/kit/go/database v1.0.3

To test how a kit repo would work. But I get the following error when running go mod tidy in my main project

github.com/michael-ottink/kit/go/database@v1.0.3: reading github.com/michael-ottink/kit/go/database/go/database/go.mod at revision go/database/v1.0.2: unknown revision go/database/v1.0.3

I am new at this and I am struggeling to understand what the problem is ? If any more info is needed I'll update the post.

this is my database.go

package database

    import (
        "gorm.io/gorm"
    )
    
    type Database struct {
        *gorm.DB
    }
    
    type Config struct {
        Driver   string
        Host     string
        Username string
        Password string
        Port     string
        Database string
        Timezone string
    }

This error occurs if you try to require it into a entirely new project with only a go.mod , go.sum and main.go.

anonymous-dev
  • 2,897
  • 9
  • 48
  • 112
  • Can you show the content of `github.com/username/kit/go/database/go.mod`? – leaf bebop Nov 18 '20 at 12:51
  • Code in your question and the link does not match. Can you please provide a reproducible example of the problem? – leaf bebop Nov 18 '20 at 13:24
  • https://github.com/michael-ottink/kit – anonymous-dev Nov 18 '20 at 13:24
  • Try modify the line `module database` to `module github.com/michael-ottink/kit/go/database` – leaf bebop Nov 18 '20 at 13:26
  • Pushed a new version with the module change and changed it in my mod file but I get the same error go: github.com/michael-ottink/kit/go/database@v1.0.3: reading github.com/michael-ottink/kit/go/database/go/database/go.mod at revision go/database/v1.0.3: unknown revision go/database/v1.0.3 – anonymous-dev Nov 18 '20 at 13:33
  • I think your git config has issue. you need to use `ssh` in git config rather than `https` i.e., `git config --global url.git@github.com:.insteadOf https://github.com/` – Em Ae Nov 22 '20 at 04:34

1 Answers1

3

The commit on v1.0.3 added an empty module named slice. The repository became multi-modules and a few more rules are implied. The documentation for a multi-modules repository is here.

Unfortunately, the first folder of the repository named /kit does not contain the modules but only its sub-folder /go.

When multiple modules are found, a tag like v1.0.3 is attributed to the repository but there is no modules which means that go get github.com//michael-ottink/kit@v1.0.3 does not do anything.

When trying to go get the subfolder with go get github.com//michael-ottink/kit/go@v1.0.3, the returned error confirms that no module was found.

To go get the repo, tag could look like go@v1.0.3

To tag each module individually, tag could be go/database/v1.0.3. When the slice module is ready, it can be tagged similarly.

It remains that when starting with modules, one repository per module is a safer bet as quoted in the documentation (here):

For all but power users, you probably want to adopt the usual convention that one repo = one module. It's important for long-term evolution of code storage options that a repo can contain multiple modules, but it's almost certainly not something you want to do by default.