go module无法下载golang.org/x

go module无法下载golang.org/x

  • go test报错
  • 解决办法:replace

go test报错

package main

import (
    "gopkg.in/gin-gonic/gin.v1"
    "net/http"
)

func main(){
    router := gin.Default()
    router.GET("/", func(c *gin.Context) {
        c.String(http.StatusOK, "Hello World")
    })
    router.Run(":8000")
}

报错信如下:
golang.org/x/[email protected] a9d3bda3a223: unrecognized import path “golang.org/x/sys” (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

[wangzheng@wangzheng-centos myweb]$ go test
go: finding github.com/gin-contrib/sse latest
go: finding github.com/ugorji/go/codec latest
go: finding github.com/golang/protobuf/proto latest
go: finding gopkg.in/yaml.v2 v2.2.2
go: finding gopkg.in/go-playground/validator.v8 v8.18.2
go: downloading gopkg.in/yaml.v2 v2.2.2
go: extracting gopkg.in/yaml.v2 v2.2.2
go: downloading gopkg.in/go-playground/validator.v8 v8.18.2
go: extracting gopkg.in/go-playground/validator.v8 v8.18.2
go: finding github.com/ugorji/go v1.1.4
go: downloading github.com/ugorji/go v1.1.4
go: extracting github.com/ugorji/go v1.1.4
go: finding github.com/golang/protobuf v1.3.1
go: downloading github.com/golang/protobuf v1.3.1
go: extracting github.com/golang/protobuf v1.3.1
go: golang.org/x/[email protected]: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: error loading module requirements

解决办法:replace

使用github上的镜像地址替换。

[wangzheng@wangzheng-centos myweb]$ go mod edit -replace=golang.org/x/[email protected]=github.com/golang/sys@latest

[wangzheng@wangzheng-centos myweb]$ cat go.mod 
module beegoLearn/myweb

go 1.12

require (
	github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect
	github.com/gin-gonic/gin v1.3.0
	github.com/golang/protobuf v1.3.1 // indirect
	github.com/mattn/go-isatty v0.0.7 // indirect
	github.com/ugorji/go v1.1.4 // indirect
	gopkg.in/gin-gonic/gin.v1 v1.3.0
	gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
	gopkg.in/yaml.v2 v2.2.2 // indirect
)

replace golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 => github.com/golang/sys v0.0.0-20190422165155-953cdadca894
[wangzheng@wangzheng-centos myweb]$

使用go test测试

[wangzheng@wangzheng-centos myweb]$ go test
go: finding github.com/gin-contrib/sse latest
go: finding github.com/ugorji/go/codec latest
go: finding github.com/golang/protobuf/proto latest
go: downloading github.com/golang/sys v0.0.0-20190422165155-953cdadca894
go: extracting github.com/golang/sys v0.0.0-20190422165155-953cdadca894
?   	beegoLearn/myweb	[no test files]

你可能感兴趣的:(golang)