Reputation: 1175
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.
Upvotes: 0
Views: 1935
Reputation: 4471
... 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.
Upvotes: 2
Reputation: 42413
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.
Upvotes: -1
Reputation: 91
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.
Upvotes: 1
Reputation: 2706
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
Upvotes: 0