Files
build-web-application-with-…/zh-tw/02.8.md
Bi-Ruei, Chiu 8efb279dcf Editorial changes for chapter 2
1. Add suitable space and colon
2. Change some parenthesis to full-width
2. Remove unnecessary numbering
2019-09-16 22:57:35 +08:00

1.3 KiB

2.8 總結

這一章我們主要介紹了 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
  • var 和 const 參考 2.2 Go 語言基礎裡面的變數和常數宣告
  • package 和 import 已經有過短暫的接觸
  • func 用於定義函式和方法
  • return 用於從函式回傳
  • defer 用於類似解構函式
  • go 用於併發
  • select 用於選擇不同型別的通訊
  • interface 用於定義介面,參考 2.6 小節
  • struct 用於定義抽象資料型別,參考 2.5 小節
  • break、case、continue、for、fallthrough、else、if、switch、goto、default 這些參考 2.3 流程介紹裡面
  • chan 用於 channel 通訊
  • type 用於宣告自訂型別
  • map 用於宣告 map 型別資料
  • range 用於讀取 slice、map、channel 資料

上面這二十五個關鍵字記住了,那麼 Go 你也已經差不多學會了。