0

I searched some article, all they used this why:

$go mod init project_name

Then created main.go and coded these:

package main

import "github.com/gin-gonic/gin"

func main() {
 r := gin.Default()
 r.GET("/ping", func(c *gin.Context) {
     c.JSON(200, gin.H{
         "message": "pong",
     })
 })
 r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

then go run main.go

but in the fact, I can't remember the lib's full name like "github.com/gin-gonic/gin", maybe I just remember gin.

So is there some way to install lib like python pip tool or go get like go mod install gin


PS:

because that I am using goland as my IDE, under the GOPATH, I can get the code tips, but under the go mod, I couldn't get it, Then I have started the question of this.

1
  • 1
    I usually copy the github.com/gin-gonic/gin from the import. Commented Sep 11, 2020 at 3:17

4 Answers 4

2

... but in the fact, I can't remember the lib's full name like "github.com/gin-gonic/gin", maybe I just remember gin.

So is there some way to install lib like python pip tool or go get like go mod install gin[?]

⛔️ No.

If you don't know full name of the package you cann't get it.

You can try to use IDE's tips (GoLand as example IDE) to find a package without <domain>/<owner>/..., import full package name and use

go mod tidy

to modify go.mod file,but IDE will try to find package in you local cache.

Sign up to request clarification or add additional context in comments.

Comments

1

I don't think so because some project have the same name, golang use project path system for your project. Usually yourhost/author/projectname, try googling your lib you try to remember with golang keyword e.g gin golang. Most of the time you will find it.

Comments

0

Checkout https://blog.golang.org/using-go-modules

The go module name is unique, so normally starts with domain name (unless it is a build-in module).

So just copy your import string's and run go get you will get it. e.g.

go get github.com/gin-gonic/gin

To update a module, use -u:

go get -u github.com/gin-gonic/gin

Comments

-1

So is there some way to install lib like python pip tool or go get like go mod install gin [?]

No. That is not how Go works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.