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 环境搭建

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

查看所有标签

猜你喜欢:

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

精通JavaScript+jQuery

精通JavaScript+jQuery

曾顺 编著 / 人民邮电出版社 / 2008-9 / 59.00元

随着Ajax技术的不断风靡,其核心技术JavaScript越来越受到人们的关注,各种JavaScript的框架层出不穷。jQuery作为JavaScript框架的优秀代表,为广大开发者提供了诸多便利。 本书从介绍JavaScript的基础知识开始,围绕标准Web的各项技术予以展开,通过大量实例对JavaScript、CSS、DOM、Ajax等 Web关键技术进行深入浅出的分析,主要内容包括J......一起来看看 《精通JavaScript+jQuery》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码