因好奇而走进go语言,让你不在只闻其声,不见其形。

https://golang.org/doc/install;这里是go语言的官网文档。吃不透英文,终究会被限制在有限的区域,一词词的吃透。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

安装包下载地址为:https://golang.org/dl/

如果打不开可以使用这个地址:https://golang.google.cn/dl/https://golang.google.cn/doc/install

想了想,具体步骤就不提了,英文内容够全了。

说一下关于SettingGOPATH的中外差别:

就像原文所说,“ If no GOPATH is set, it is assumed to be $HOME/go on Unix systems and %USERPROFILE%\go on Windows.”

那么这个GOPATH居然是在环境变量的用户变量中;

那么,原文中:

Your workspace can be located wherever you like, but we'll use C:\go-work in this example.

NOTE: GOPATH must not be the same path as your Go installation.

  • Create folder at C:\go-work.
  • Right click on "Start" and click on "Control Panel". Select "System and Security", then click on "System".
  • From the menu on the left, select the "Advanced systems settings".
  • Click the "Environment Variables" button at the bottom.
  • Click "New" from the "User variables" section.
  • Type GOPATH into the "Variable name" field.
  • Type C:\go-work into the "Variable value" field.
  • Click OK.

这段就是说将GOPATH这个环境变量的值由原来的%USERPROFILE%\go替换为你的go工作空间的目录。保存环境变量更改后,记得重启电脑是其生效(win10)。

原文中是这样使test.go生效的并测试的:

Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.

Create your workspace directory, %USERPROFILE%\go. (If you'd like to use a different directory, you will need to set the GOPATH environment variable.)

Next, make the directory src\hello inside your workspace, and in that directory create a file named hello.go that looks like:

package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}

Then build it with the go tool:

C:\> cd %USERPROFILE%\go\src\hello
C:\Users\Gopher\go\src\hello> go build

The command above will build an executable named hello.exe in the directory alongside your source code. Execute it to see the greeting:

C:\Users\Gopher\go\src\hello> hello
hello, world

If you see the "hello, world" message then your Go installation is working.

You can run go install to install the binary into your workspace's bin directory or go clean -i to remove it.

Before rushing off to write Go code please read the How to Write Go Code document, which describes some essential concepts about using the Go tools.

但是,按旧有方式,还可在终端执行:go run hello.go

 个人安装GO1.13.6版本指南手册之搭建环境 go

 

 使用原文中的生成hello.exe文件得使用当前目录相对路径执行hello.exe这种方式。

 

更新:

1. 因为go version >= 1.13,所以go env -w GO111MODULE=on修改相应依赖模式,go env查看

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄