Go(又称 Golang)是 Google 的 Robert Griesemer,Rob Pike 及 Ken Thompson 开发的一种静态强类型、编译型语言。
Go 语言语法与 C 相近,但功能上有:内存安全,GC(垃圾回收),结构形态及 CSP-style 并发计算。
特点有着这样的简称:Go=C+Python 大概知道怎样了吗?
一、Go环境安装
、下载链接:Downloads - The Go Programming Language
2、安装后会自动新增环境变量,如果没有就自行添加。mac、linux亦是如此,查看go版本
go version
# 设置为 七牛云 代理
go env -w GOPROXY=https://goproxy.cn,direct
二、GoLand
1、下载链接:下载 GoLand
2、创建项目,需要对GOROOT:设置go环境变量的根目录即可
3、创建HelloWord.go
package main
import "fmt"
func main() {
fmt.Println("HelloWord")
}
注意导入包是:package main
三、命令行
1、运行&编译命令
go run HelloWord.go:运行程序
go build HelloWord.go:编译为exe
PPL@DESKTOP-KA2V9FJ MINGW64 /d/project/awesomeProject
$ go run HelloWord.go
HelloWord
PPL@DESKTOP-KA2V9FJ MINGW64 /d/project/awesomeProject
$ go build HelloWord.go
PPL@DESKTOP-KA2V9FJ MINGW64 /d/project/awesomeProject
$ ./HelloWord.exe
HelloWord
2、Go语法是不区分平台的,需要将两个环境变量控制即可
①G00S:设定运行的平台
- 1. mac: GOOS=darwin2
- 2. linux: GooS=linux
- 3. windows :GOOS=windows
②GOARCH:目标平台的体系构架
- 1.386: GOARCH=386
- 2.amd64: GOARCH=amd64
- 3.arm : GOARCH=arm
3、go env 查看环境变量
# 设置 go env 环境变量
go env -w key=xxx
如果还想了解更多命令直接输入go:
C:\Users\Administrator>go
Go is a tool for managing Go source code.
Usage:
go <command> [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 <command>" for more information about a command.
Additional help topics:
buildconstraint build constraints
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
packages package lists and patterns
private configuration for downloading non-public code
testflag testing flags
testfunc testing functions
vcs controlling version control with GOVCS
Use "go help <topic>" for more information about that topic.
C:\Users\Administrator>