golang 环境搭建

栏目: Go · 发布时间: 5年前

内容简介:Linux 下环境变量设置export GOROOT=/opt/goexport GOPATH=/home/ubuntu/goCode

下载地址: https://golang.google.cn/dl/

下载:go1.10.3.windows-amd64.msi    

安装

golang 环境搭建 golang 环境搭建 golang 环境搭建

新建文件

golang 环境搭建

环境配置

查看环境变量

golang 环境搭建

GOROOT : golang安装目录 D:\Go

GOPATH  :保存源码路径,开发代码路径,如F:\work\goCode

golang 环境搭建

在环境变量 PATH下添加 : D:\Go\bin 和 F:\work\goCode\bin

golang 环境搭建

重启cmd

golang 环境搭建

Linux 下环境变量设置

export GOROOT=/opt/go

export GOPATH=/home/ubuntu/goCode

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

测试环境

在  F:\work\goCode\src\HelloWorld 目下新建 main.go文件,编写如下代码

package main

import(
	"fmt"
)


func main(){
	fmt.Println("Hello World")
}

运行main.go

golang 环境搭建

编译

golang 环境搭建

在目录下生成

golang 环境搭建

安装

golang 环境搭建 golang 环境搭建

自动生成文档

golang 环境搭建

浏览器输入

golang 环境搭建 golang 环境搭建

在线查看文档

http://godoc.org/github.com/golang/protobuf/proto

IDE 环境安装

安装 vs code 及 golang 插件

VSCode 下载 :  https://code.visualstudio.com/

安装:VSCodeUserSetup-x64-1.26.1.exe

golang 环境搭建
golang 环境搭建 golang 环境搭建

查看版本号:cmd运行

go version

安装 go 插件

golang 环境搭建 golang 环境搭建

安装第三方插件,进行智能提示,debug等。

golang 环境搭建 golang 环境搭建 golang 环境搭建

部分安装成功

golang 环境搭建

输出信息如下:

Installing 10 tools at F:\work\goCode\bin

gocode

gopkgs

go-outline

go-symbols

guru

gorename

dlv

godef

goreturns

golint

Installing github.com/mdempsky/gocode SUCCEEDED

Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED

Installing github.com/ramya-rao-a/go-outline FAILED

Installing github.com/acroca/go-symbols FAILED

Installing golang.org/x/tools/cmd/guru FAILED

Installing golang.org/x/tools/cmd/gorename FAILED

Installing github.com/derekparker/delve/cmd/dlv SUCCEEDED

Installing github.com/rogpeppe/godef SUCCEEDED

Installing github.com/sqs/goreturns FAILED

Installing github.com/golang/lint/golint FAILED

6 tools failed to install.

go-outline:

Error: Command failed: D:\Go\bin\go.exe get -u -v github.com/ramya-rao-a/go-outline

github.com/ramya-rao-a/go-outline (download)

Fetching https://golang.org/x/tools/go/buildutil?go-get=1

https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1: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/buildutil: unrecognized import path "golang.org/x/tools/go/buildutil" (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1: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.)

github.com/ramya-rao-a/go-outline (download)

Fetching https://golang.org/x/tools/go/buildutil?go-get=1

https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1: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/buildutil: unrecognized import path "golang.org/x/tools/go/buildutil" (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1: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.)

go-symbols:

Error: Command failed: D:\Go\bin\go.exe get -u -v github.com/acroca/go-symbols

github.com/acroca/go-symbols (download)

Fetching https://golang.org/x/tools/go/buildutil?go-get=1

https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1: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/buildutil: unrecognized import path "golang.org/x/tools/go/buildutil" (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1: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.)

github.com/acroca/go-symbols (download)

Fetching https://golang.org/x/tools/go/buildutil?go-get=1

https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1: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/buildutil: unrecognized import path "golang.org/x/tools/go/buildutil" (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1: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.)

guru:

Error: Command failed: D:\Go\bin\go.exe get -u -v golang.org/x/tools/cmd/guru

Fetching https://golang.org/x/tools/cmd/guru?go-get=1

https fetch failed: Get https://golang.org/x/tools/cmd/guru?go-get=1: dial tcp 216.239.37.1: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/cmd/guru: unrecognized import path "golang.org/x/tools/cmd/guru" (https fetch: Get https://golang.org/x/tools/cmd/guru?go-get=1: dial tcp 216.239.37.1: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.)

Fetching https://golang.org/x/tools/cmd/guru?go-get=1

https fetch failed: Get https://golang.org/x/tools/cmd/guru?go-get=1: dial tcp 216.239.37.1: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/cmd/guru: unrecognized import path "golang.org/x/tools/cmd/guru" (https fetch: Get https://golang.org/x/tools/cmd/guru?go-get=1: dial tcp 216.239.37.1: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.)

gorename:

Error: Command failed: D:\Go\bin\go.exe get -u -v golang.org/x/tools/cmd/gorename

Fetching https://golang.org/x/tools/cmd/gorename?go-get=1

https fetch failed: Get https://golang.org/x/tools/cmd/gorename?go-get=1: dial tcp 216.239.37.1: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/cmd/gorename: unrecognized import path "golang.org/x/tools/cmd/gorename" (https fetch: Get https://golang.org/x/tools/cmd/gorename?go-get=1: dial tcp 216.239.37.1: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.)

Fetching https://golang.org/x/tools/cmd/gorename?go-get=1

https fetch failed: Get https://golang.org/x/tools/cmd/gorename?go-get=1: dial tcp 216.239.37.1: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/cmd/gorename: unrecognized import path "golang.org/x/tools/cmd/gorename" (https fetch: Get https://golang.org/x/tools/cmd/gorename?go-get=1: dial tcp 216.239.37.1: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.)

goreturns:

Error: Command failed: D:\Go\bin\go.exe get -u -v github.com/sqs/goreturns

github.com/sqs/goreturns (download)

Fetching https://golang.org/x/tools/imports?go-get=1

https fetch failed: Get https://golang.org/x/tools/imports?go-get=1: dial tcp 216.239.37.1: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/imports: unrecognized import path "golang.org/x/tools/imports" (https fetch: Get https://golang.org/x/tools/imports?go-get=1: dial tcp 216.239.37.1: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.)

github.com/sqs/goreturns (download)

Fetching https://golang.org/x/tools/imports?go-get=1

https fetch failed: Get https://golang.org/x/tools/imports?go-get=1: dial tcp 216.239.37.1: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/imports: unrecognized import path "golang.org/x/tools/imports" (https fetch: Get https://golang.org/x/tools/imports?go-get=1: dial tcp 216.239.37.1: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.)

golint:

Error: Command failed: D:\Go\bin\go.exe get -u -v github.com/golang/lint/golint

github.com/golang/lint (download)

Fetching https://golang.org/x/lint?go-get=1

https fetch failed: Get https://golang.org/x/lint?go-get=1: dial tcp 216.239.37.1: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/lint: unrecognized import path "golang.org/x/lint" (https fetch: Get https://golang.org/x/lint?go-get=1: dial tcp 216.239.37.1: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.)

github.com/golang/lint (download)

Fetching https://golang.org/x/lint?go-get=1

https fetch failed: Get https://golang.org/x/lint?go-get=1: dial tcp 216.239.37.1: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/lint: unrecognized import path "golang.org/x/lint" (https fetch: Get https://golang.org/x/lint?go-get=1: dial tcp 216.239.37.1: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.)

发现代码都下载成功,但部分未安装

golang 环境搭建

重新安装

新建如下目录 F:\work\goCode\src\golang.org\x

在  F:\work\goCode\src\golang.org\x 目录下 git 获取代码

git clone http://github.com/golang/tools

git clone http://github.com/golang/lint

下载完成后,在F:\work\goCode目录下执行cmd命令

go install golang.org/x/tools/cmd/gorename

go install golang.org/x/tools/cmd/guru

go install github.com/ramya-rao-a/go-outline

go get -u -v github.com/newhook/go-symbols   下载成功,但没有安装,用下面命令手动安装

go install github.com/newhook/go-symbols

go install github.com/sqs/goreturns

go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv

上面安装的包也可以通过以下方式下载:

go get -u -v github.com/nsf/gocode

go get -u -v github.com/rogpeppe/godef

go get -u -v github.com/tpng/gopkgs

go get -u -v golang.org/x/tools/cmd/gorename   

go get -u -v golang.org/x/tools/cmd/guru  

go get -u -v github.com/ramya-rao-a/go-outline

go get -u -v github.com/newhook/go-symbols   

go get -u -v sourcegraph.com/sqs/goreturns

go get -u -v github.com/golang/lint/golint

F5 debug 调试插件

这些内容最终目的是要在gopath中bin文件夹中生成一些exe文件。

golang 环境搭建

配置 VSCode

golang 环境搭建
golang 环境搭建

在用户设置中粘贴如下 json 语句

{

"go.buildOnSave": true,

"go.lintOnSave": true,

"go.vetOnSave": true,

"go.buildTags": "",

"go.buildFlags": [],

"go.lintFlags": [],

"go.vetFlags": [],

"go.coverOnSave": false,

"go.useCodeSnippetsOnFunctionSuggest": false,

"go.formatOnSave": true,

"go.formatTool": "goreturns",

"go.goroot": "D:\\Go",

"go.gopath": "F:\\work\\goCode",

"go.gocodeAutoBuild": false

}

测试

golang 环境搭建 golang 环境搭建 golang 环境搭建 golang 环境搭建 golang 环境搭建 golang 环境搭建

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

怎样解题

怎样解题

[美] G. 波利亚 / 涂泓、冯承天 / 上海科技教育出版社 / 2002-6 / 16.00元

《怎样解题:数学教学法的新面貌》是数学家波利亚论述中学数学教学法的普及名著,对数学教育产生了深刻的影响。波利亚认为中学数学教育的根本宗旨是教会年轻人思考,他把“解题”作为培养学生数学才能和教会他们思考的一种手段和途径。这本书是他专门研究解题的思维过程后的结晶。全书的核心是他分解解题的思维过程得到的一张“怎样解题”表。作者在书中引导学生按照“表”中的问题和建议思考问题,探索解题途径,进而逐步掌握解题......一起来看看 《怎样解题》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

SHA 加密
SHA 加密

SHA 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具