2

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?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 1
    Take a look at [https://stackoverflow.com/questions/128035/how-do-i-pull-from-a-git-repository-through-an-http-proxy](https://stackoverflow.com/questions/128035/how-do-i-pull-from-a-git-repository-through-an-http-proxy) – putu Aug 16 '17 at 06:44

2 Answers2

2

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")

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @ЮрийШиповалов Did you set the environment variable `HTTP_PROXY/HTTPS_PROXY`? Did you use an http URL for the proxy? – VonC Aug 16 '17 at 08:53
  • C:\Users\YShipovalov\Projects\src\helloworld>go run main.go ..\github.com\gin-gonic\gin\binding\default_validator.go:11:2: cannot find packa ge "gopkg.in/go-playground/validator.v8" in any of: C:\Users\YShipovalov\Projects\src\github.com\gin-gonic\gin\vendor\gopkg. in\go-playground\validator.v8 (vendor tree) after run main.go. All packages are downloaded in GOPATH – Юрий Шиповалов Aug 16 '17 at 10:52
  • @ЮрийШиповалов So the go get has worked? (sice you do have a github.com\gin-gonic\gin). Can you try glide or govendor (https://github.com/gin-gonic/gin/issues/757#issuecomment-265369437) in order to make sure gin has all its dependencies? – VonC Aug 16 '17 at 10:59
0

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!

Saeed Falsafin
  • 556
  • 6
  • 15