Go
1 基础知识
1.1 简介
- Go是一种开放源代码编程语言
- Go可轻松构建简单、可靠且高效的软件
1.2 Go语言的特点
- Go富有表现力、简介、整洁且高效
- Go的并发机制使编写程序可轻松地从多核和联网的机器中获得最大收益
- Go的新颖类型系统可构建灵活的模块化程序
- Go可以快速编译成机器码且具有便利的垃圾回收和运行时反射功能
- Go是一种快熟、静态类型的编程语言,但有动态类型解析语言的效果
2 最佳实践
2.1 环境准备
2.1.1 部署系统环境
OS = CentOS 8.x x86_64
Host Name = any
IP Address = any
2.1.2 下载安装包
cd ~ wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
其他版本请从以下页面下载,
https://golang.org/dl/
2.2 部署软件包
2.2.1 部署软件包到目录
cd ~ tar -C /usr/local/ -xf go1.14.4.linux-amd64.tar.gz
2.2.2 配置环境变量
vim /etc/profile.d/golan.sh
输入如下配置,
export GOLAN_HOME=/usr/local/go export PATH=${GOLAN_HOME}/bin:$PATH
另外,如果想快速配置,可使用如下命令,
echo 'export GOLAN_HOME=/usr/local/go' > /etc/profile.d/golan.sh echo 'export PATH=${GOLAN_HOME}/bin:$PATH' >> /etc/profile.d/golan.sh
配置完成后,可使用如下命令导入环境变量,
source /etc/profile
配置完成后,建议使用如下命令确认环境变量生效,
go version
可见如下输出,
go version go1.14.4 linux/amd64
2.2.3 获取命令行帮助
go help
可见如下显示,
Go is a tool for managing Go source code. Usage: go [arguments] The commands are: bug start a bug report build compile packages and dependencies clean remove object files and cached files doc show documentation for package or symbol env print Go environment information fix update packages to use new APIs fmt gofmt (reformat) package sources generate generate Go files by processing source get add dependencies to current module and install them install compile and install packages and dependencies list list packages or modules mod module maintenance run compile and run Go program test test packages tool run specified go tool version print Go version vet report likely mistakes in packages Use "go help " for more information about a command. Additional help topics: buildmode build modes c calling between Go and C cache build and test caching environment environment variables filetype file types go.mod the go.mod file gopath GOPATH environment variable gopath-get legacy GOPATH go get goproxy module proxy protocol importpath import path syntax modules modules, module versions, and more module-get module-aware go get module-auth module authentication using go.sum module-private module configuration for non-public modules packages package lists and patterns testflag testing flags testfunc testing functions Use "go help " for more information about that topic.
2.3 尝试编译代码
2.3.1 创建代码
cd ~/ vim hello.go
加入如下代码,
package main import "fmt" func main() { fmt.Printf("hello, world\n") }
2.3.2 编译代码
cd ~/ go build hello.go
2.3.3 测试运行
cd ~/ ./hello
可见如下显示,
hello, world
参阅文档
===================
GO的安装包下载
—————
https://golang.org/dl/
安装方法
—————
https://golang.org/doc/install
官方首页
—————
https://golang.org/
动态语言与静态语言的区别
——————-
https://www.jianshu.com/p/355494d8bd08
没有评论