Go (或Golang )是Google 在2007 年开发的一种开源编程语言,出自Robert Griesemer 、Rob Pike 和Ken Thompson 之手。2009 年11 月10 日, Google Open Source Blog 向全球发布了这款语言:公告指出Go 的主要目标是“兼具Python 等动态语句的开发速度和C 或C ++等编译型语言的性能与安全性”。
Go 使用编译器来编译代码。编译器将源代码编译成二进制(或字节码)格式: 在编译代
码时, 编译器检查错误、优化性能并输出可在不同平台上运行的二进制文件。要创建并运行
Go 程序, 程序员必须执行如下步骤。
- 使用文本编辑器创建Go 程序。
- 保存文件。
- 编译程序。
- 运行编译得到的可执行文件。
这不同于Python 、Ruby 和JavaScript 等语言,它们不包含编译步骤。有关使用编译器的优缺点,将在第2 章介绍。Go 自带了编译器, 因此无须单独安装编译器。
安装GoGo 支持FreeBSD 、Linux 、Windows 和macOS 等操作系统。
安装实例与环境均采用Windows7 64bit环境下。
本教程的安装环境为:Windows7 64位;go1.17.3.windows-amd64;goland-2021.1.3、Git-2.34.1-64-bit
安装go1.17.3.windows-amd64

安装goland-2021.1.3

安装Git-2.34.1-64-bit

配置环境
- 其中1 2 3 4为配置go环境,a为配置git环境
配置go
- 执行go env命令

配置GO111MODULE
$ go env -w GO111MODULE=on
配置GOPROXY代理
$ go env -w GOPROXY=
检查GOPATH、GOROOT配置是否正确。
其中GOPATH为项目目录,目录内新建3个文件夹,分别是src、bin、pkg。
其中GOROOT为go安装路径


源码

编译并运行(go run demo1.go)
当然,如果你想要生成可执行的二进制文件你可以这么操作

生成可执行的二进制文件
首先编译成二进制文件,通过观察可以看到生成的为禁止文件大小为1.9M,通过./demo1.exe可直接执行,也可以把这个可执行程序发送给你的朋友试试。
下面,我们将学习数据类型,并将持续更新。