Do I have to install gin framework in every new folder I create in visual Studio code for Golang programmes?

huangapple go评论68阅读模式
英文:

Do I have to install gin framework in every new folder I create in visual Studio code for Golang programmes?

问题

我已经在我的桌面上的一个名为Gingo的不同文件夹中安装了gin框架。我正在学习如何通过Gin框架构建一个Web RESTful API,通过开始实现支持我们的Go Music所需的后端代码。但是我在桌面上为这个Go Music创建了另一个名为backend的文件夹,所以我是否也需要在这个文件夹中安装gin框架呢?该项目可以在https://github.com/gin-gonic/gin找到。

英文:

I have already installed gin framework in a different folder on my desktop named Gingo. I am learning how to build a web RESTful API through the Gin framework,
by starting the implementation of the backend code that is needed to support our Go Music.
But I have created another folder on my desktop for this Go Music named backend, so do I have to install gin framework in this folder as well?
The project can be found at https://github.com/gin-gonic/
gin.

答案1

得分: 2

在Go语言中,你可以通过使用Go模块来使用外部库和框架。在backend文件夹(或者你的Go代码的根文件夹)中运行go mod init name-of-project来初始化你的项目。

现在,如果你想将gin添加到你的项目中,可以运行go get github.com/gin-gonic/gin,这将把gin添加到你的项目依赖中(你可以在项目根目录的go.mod文件中看到所有的依赖)。

gin的代码将被下载并放置在你的GOPATH(通常是~/go)的pkg文件夹中。这样,代码只需要下载一次,每次导入时都会使用已经存在的代码。不过,你每次都需要将它添加到你的项目依赖中。

了解更多关于Go模块的信息,请访问:https://zetcode.com/golang/module/

英文:

The way you use external libraries and frameworks in Go is by using Go modules. Initialise your project by running go mod init name-of-project in the backend folder (or whatever the root folder is for your Go code).

Now, if you want to add gin to your project, you can run go get github.com/gin-gonic/gin, which adds gin to the dependencies of your project (you can see all dependencies in the go.mod file in the project root).

The gin code will be downloaded and placed in the pkg folder in your GOPATH (often ~/go). This way the code has to be downloaded only once, and every time you import it it is simply using the already present code. You do have to add it to the dependencies of your project every time though.

For more information about Go modules: https://zetcode.com/golang/module/

答案2

得分: 2

我认为你应该在每个项目中安装它,因为在我的观点中,Golang的框架只是第三方库。但是如果你想在你的系统上安装它,你可以尝试这个。也许这会成为你编程之旅的新起点。

英文:

i think you must install in every project, in my opinion because framework on golang just thrid party labrary. but if you want to install on your system you can try this. maybe its can be new journery on your programming

huangapple
  • 本文由 发表于 2022年6月2日 15:24:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/72472218.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定