本篇單純個人學習筆記
若有錯誤請指正
不要炮我
- donwload: https://golang.org/dl/
- Linux download:$ sudo apt-get install golang
- setting(win7):
- 環境變數設定中,把Go的執行檔位置(default為C:\Go\bin)加入變數"PATH"的變數值中,才能在任意資料夾執行go run或go build...
- default環境變數(GOPATH = %USERPROFILE%\go) => C:\Users\xxx\go
- 下載的pkg與src都會在這裡
- IDE:TBD,暫時使用notepad++
- func
- 名稱為大寫開頭:public function
- example:func GetTable => 外部可調用Test.GetTable
- 名稱為小寫開頭:private function
- example:func getData
- 名稱為大寫開頭:public function
- variable type
- type寫在變數後方,e.g. var msg string
- os.Args
- [0]為執行檔名稱
- [1]開始才是使用者帶入的引數
- import
- 相同與C#的using,Javascript的import
- import後可用( )把要import的內容包起來
- import的東西要加" "
- packages
- official:https://golang.org/pkg/
- Popular & standard:https://godoc.org/
- Terms / Reserved
- nil => 可想像成null,某些型態變數未賦與初始值就為nil
- defer
- func return前會執行
- reference and example: https://www.evanlin.com/golang-know-using-defer/
- panic, recover...
- reference and example: https://openhome.cc/Gossip/Go/DeferPanicRecover.html
- iota
- 計數器,當const關鍵字出現時被重置為0,每新增一行將iota計數一次
- 常用於列舉
- example
- type ErrorType int
- const (
- NotFound = iota //0
- Missing //1
- Unknown //2
- )
- other reference
未完待續
文章標籤
全站熱搜
留言列表