簡介
- Go 是一個開源的編程語言,它能讓構造簡單、可靠且高效的軟件變得容易。
Golang特別之處
- 沒有
對象
,沒有繼承、多態、泛型、沒有try/catch
- 有接口、函數式編程、csp併發模型(goroutine+channel)
- golang語法簡單,用好golang不容易,由於要調整三觀
網站
- 官網
- 中文社區 中國社區
- 官方下載
- 基礎教程
- 系列教程
方向
- 區塊鏈研發工程師、GO服務器端工程師、遊戲軟件工程師、Golang分佈式/雲計算軟件工程師
安裝
- Windows環境
- 下載
XXX.msi
文件 下一步 -> 下一步
就好了
- Linux
- 先解壓安裝包
tar -xzf go1.11.4.linux-amd64.tar.gz -C /usr/local
-> 在配置環境變量export PATH=$PATH:/usr/local/go/bin
- Mac OS X
.pkg
結尾的安裝包直接雙擊來完成安裝,安裝目錄在 /usr/local/go/
Go 語言最主要的特性:
- 自動垃圾回收
- 更豐富的內置類型
- 函數多返回值
- 錯誤處理
- 匿名函數和閉包
- 類型和接口
- 併發編程
- 反射
- 語言交互性
編寫第一個go程序
package main //每個 Go 文件都應該在開頭進行 package name 的聲明
import "fmt" //引入了 fmt 包,用於在 main 函數裏面打印文本到標準輸出
func main(){ //整個程序就是從 main 函數開始運行的
//單行註釋
/*多行註釋*/
fmt.Println("hello,world!")
}
$ go run hello.go
運行 hello.go
Go語言基礎語法
- Go程序能夠由多個標記組成,能夠是關鍵字,標識符,常量,字符串,符號
關鍵字
break |
default |
func |
interface |
select |
case |
defer |
go |
map |
struct |
chan |
else |
goto |
package |
switch |
const |
fallthrough |
if |
range |
type |
continue |
for |
import |
return |
var |
append |
bool |
byte |
cap |
close |
complex |
complex64 |
complex128 |
uint16 |
copy |
false |
float32 |
float64 |
imag |
int |
int8 |
int16 |
uint32 |
int32 |
int64 |
iota |
len |
make |
new |
nil |
panic |
uint64 |
print |
println |
real |
recover |
string |
true |
uint |
uint8 |
uintptr |