go get -u -t -v github.com/golang/lint/golint github.com/golang/lint (download) Fetching https://golang.org/x/tools/go/gcexportdata?go-get=1 https fetch failed: Get https://golang.org/x/tools/go/gcexportdata?go-get=1: dial tcp 172.217.10.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. package golang.org/x/tools/go/gcexportdata: unrecognized import path "golang.org/x/tools/go/gcexportdata" (https fetch: Get https://golang.org/x/tools/go/gcexportdata?go-get=1: dial tcp 172.217.10.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
由于国内环境被墙了导致下载失败,此时可以用以下方式解决:
1 2 3 4 5 6 7 8
# 创建目录 mkdir -p $GOPATH/src/golang.org/x # 进入 cd$GOPATH/src/golang.org/x # 从github拉取备份下来,具体可以在这里找到golang的源码备份:https://github.com/golang git clone https://github.com/golang/tools.git # 再安装一次 go get golang.org/x/tools
某些特性
定义并赋值
1 2 3
cat := "merry" a := 111 chats := []string{"A","B","C"}
package main import"fmt" funcmain() { //这是我们使用range去求一个slice的和。使用数组跟这个很类似 nums := []int{2, 3, 4} sum := 0 for _, num := range nums { sum += num } fmt.Println("sum:", sum) //在数组上使用range将传入index和值两个变量。上面那个例子我们不需要使用该元素的序号,所以我们使用空白符"_"省略了。有时侯我们确实需要知道它的索引。 for i, num := range nums { if num == 3 { fmt.Println("index:", i) } } //range也可以用在map的键值对上。 kvs := map[string]string{"a": "apple", "b": "banana"} for k, v := range kvs { fmt.Printf("%s -> %s\n", k, v) } //range也可以用来枚举Unicode字符串。第一个参数是字符的索引,第二个是字符(Unicode的值)本身。 for i, c := range"go" { fmt.Println(i, c) } }