Go and MongoDB
Golang Swagger Gin

Golang missing module

The steps to do to set up a new Go project with modules:

  1. Have Go installed. Latest version preferably, best >= v1.13 which Go modules the default. For go1.11 and above you will have to do some extra steps to enable Go modules.
  2. Create a new folder for your project. Preferably NOT in GOPATH. By default GOPATH is ~/go, so create your own projects folder, e.g. mkdir ~/projects and then mkdir ~/projects/myproject.
  3. All further commands are run from the new projects root, so best switch there: cd ~/projects/myproject
  4. In the newly created folder run go mod init projectPath where projectPath should be the URL of your future git repo (e.g. github.com/myname/myproject). This will create the go.mod file in the current folder. It will contain the module name you used in go mod init and the currently installed go version as a minimum version. (Don't worry about that for now, it won't get in your way.) If you don't plan on ever releasing your project, you can name your project anything. But if that ever conflicts with another package or module name, you are in trouble.
  5. Now you can run go get github.com/gin-gonic/gin (don't use -u, that is dangerous as it update all sub-dependencies instead of using the dependencies the gin developers used). This should add github.com/gin-gonic/gin to your go.mod file as a requirement. If you want to update a dependency, just call go get depPath again. It will update the dependency version in your go.mod file to the latest version available. If you want to up-/downgrade to a specific version use go get depPath@vX.Y.Z.
  6. Create your main.go and use github.com/gin-gonic/gin in there.
  7. Use go mod tidy to remove all unused imports or add missing ones to go.mod. (Usually you don't need to edit go.modgo mod tidy will do that for you.) It will also tidy up your go.sum file which holds check sums for all your dependencies. You can have a look at the file, but will (usually) never have to edit it. go mod tidy will do that for you.
  8. In Goland the most important is to make sure Go modules integration is enabled. The other settings should be correct by default.
  9. If you still have problems with the dependencies, you can try a go clean -modcache. It will clear your entire local modules cache, so you need to download all of it again. This can sometimes help if the modules cache got messed up somehow. Should not happen normally, though.

Hope this helps. If it doesn't, let me know so I can add the missing parts.


Feed You can follow this conversation by subscribing to the comment feed for this post.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)