no matching versions for query "latest" with a local package

Viewed 17610
go version go1.15.2 darwin/amd64

within my folder I have two files: main.go and user.go along with other files such as go.mod, go.sum etc.

when trying to import the package from user.go I get the error in my imports:

no matching versions for query "latest"

user.go

package user

import (
    "os"
    "os/user"
    "path/filepath"
)

main.go

import (
    "fmt"
    "bufio"
    "github.com/ctfrancia/go-dot/user" // <--- error here
    // ...
)

I tried following some suggestions such as go clean -modcache as suggested in a git hub issue

I'm using gomods so I don't want to disable it. Thanks

2 Answers

so my mistake was that the folder in the directory is the package name... well best practice:

so: goApplication/pkg/hello all the subsequent .go files should have package hello at the top

Your files user.go and main.go are in same directory, in golang if you want to work with custom packages you have to create directories with the same name as your package name in your case your directory structure will be something like:

goApplication/rootDir
- main.go
- user
-- user.go

Note: You can also use pkg/user directory but it is not mandatory for small projects and community has positive as well as negative remarks for this layout structure.

Related