I have problem with importing gin package into my Go project.
Code:
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
}
I'm using go get
command to install gin package, but it doesn't work.
C:\Users\YShipovalov\Desktop\Golang\helloworld>go get -v github.com/gin-gonic/gi
n
Fetching https://gopkg.in/go-playground/validator.v8?go-get=1
https fetch failed: Get https://gopkg.in/go-playground/validator.v8?go-get=1: di
al tcp 45.33.37.13:443: connectex: No connection could be made because the targe
t machine actively refused it.
package gopkg.in/go-playground/validator.v8: unrecognized import path "gopkg.in/
go-playground/validator.v8" (https fetch: Get https://gopkg.in/go-playground/val
idator.v8?go-get=1: dial tcp 45.33.37.13:443: connectex: No connection could be
made because the target machine actively refused it.)
Fetching https://gopkg.in/yaml.v2?go-get=1
https fetch failed: Get https://gopkg.in/yaml.v2?go-get=1: dial tcp 45.33.37.13:
443: connectex: No connection could be made because the target machine actively
refused it.
package gopkg.in/yaml.v2: unrecognized import path "gopkg.in/yaml.v2" (https fet
ch: Get https://gopkg.in/yaml.v2?go-get=1: dial tcp 45.33.37.13:443: connectex:
No connection could be made because the target machine actively refused it.)
I have set proxy settings in git,so can this be a problem?
Try with:
go get gopkg.in/gin-gonic/gin.v1
That will import a fixed version of that framework.
See for instance "Build RESTful API service in golang using gin-gonic framework"
But if you have proxy issue, that import should fail too.
As seen in "Building Go Web Applications and Microservices Using Gin", go get -u github.com/gin-gonic/gin
should work too.
Try removing proxy directive in your .gitconfig
.
Try instead setting HTTP_PROXY/HTTPS_PROXY
(make sure to use http url in both cases for the variables, as I illustrate in "this answer")
Fixed version is not that important! The: $ go get github.com/gin-gonic/gin
Should work correctly!! Fixed version is for when you want n specific version!