golang 环境搭建

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

内容简介: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 环境搭建

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

查看所有标签

猜你喜欢:

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

我在阿里做运营

我在阿里做运营

芮曦(@小马鱼) / 电子工业出版社 / 2018-7 / 59.00元

《我在阿里做运营》是一本散发着浓浓阿里味儿的运营书。作者进入互联网行业7年,曾就职于携程、阿里巴巴等大平台,也服务过小微企业、传统企业及诸多职场新人。不仅经历过各类运营岗,也经历过市场、品牌等岗位,对精细化运营、数据化运营和低成本运营有着深刻见解。 本书展示了在阿里这样的大平台做运营工作的真实场景,也提炼了适用于小微企业的经验,以及让运营新人快速上手的技能和自我修养、职业规划。一起来看看 《我在阿里做运营》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器