Go 語言入門介紹,底下是大綱:
* Go 語言誕生 * Go 語言優勢 * Go 語言選擇 * 誰在用 Go 語言
最後會提到 goroutine 及 channel 這兩大特性。如果對 Go 語言有興趣,可以參考線上課程: https://blog.wu-boy.com/golang-online-course/
Go 語⾔簡介吳柏毅 Bo-Yi Wuhttps://blog.wu-boy.com/
View Slide
Mediatek EngineerDevOpsGolang, PHP, Node.js ..Some open sourceGiteaGinDroneappleboy @GitHubappleboy @twitterappleboy @slideshareappleboy46 @facebookAbout Me2
2017 Google Survey Resulthttps://blog.golang.org/survey2017-results
Go 基本簡介Go 語⾔誕⽣Go 語⾔優勢Go 語⾔選擇誰在⽤ Go 語⾔
Robert Griesemer, Rob Pike 和 Ken Thompson
Go 語⾔初期發展四件事情讓 Go 發展得更好
1. Ian Lance Taylor 加入
2. Russ Cox 在 2008 年加入實現了 http.HandlerFunc 及 io 接⼝
3. 安全專家 Adam Langleygolang.org 網站及 build dashboard
4. Docker 及 Kubernets 使⽤ GO2013 年及 2014 年
Golang in China
Go 發佈週期 (半年⼀版)2013/05 1.12013/12 1.22014/06 1.32014/12 1.42015/08 1.5 (Google 規定以後每半年發佈⼀版)2016/02 1.62016/08 1.72017/02 1.82017/08 1.92018/02 1.10 (最新版)
Go 語⾔發展歷史(漫畫版)https://goo.gl/jGcwXK
為什麼設計 Go 語⾔根據 Rob Pike ⼤神描述 …
Google 遇到的問題⼤量的 C++ 代码,同時引入 Java 和 Python成千上萬的⼯程师 (每個⼈風格不同)數百萬的程式碼 (如何減少代碼產量)分散式編譯系統 (交叉編譯速度 …)數百萬的伺服器 (部署時間 …)
Go 語⾔特性沒有物件導向 (無繼承特性)強制類型Function 和 Method没有錯誤處理⽤字⾸來區別可否存取不⽤的 Import 或變數會引起編譯錯誤完整的標準函式⽀援 UTF-8 格式
沒有物件導向 (無繼承特性)
強制類型
Function 和 Method
没有錯誤處理
⽤字⾸來區別可否存取
Import 錯誤
Go at Google: Language Designin the Service of SoftwareEngineeringhttps://talks.golang.org/2012/splash.article
Go 優勢學習曲線開發及執⾏效率由 Google 維護部署⽅便跨平台編譯內建 Coding Style, Testing 等⼯具多核⼼處理
誰在⽤ Go 語⾔
Go ⼤型專案https://github.com/golang/go/wiki/Projects
Why Gohttps://github.com/golang/go/wiki/whygo
Switched from other languages. PHP, Python, Node.js, Java, C++https://github.com/golang/go/wiki/FromXToGo
5 Reasons Why We switched from Python To Gohttps://hackernoon.com/5-reasons-why-we-switched-from-python-to-go-4414d5f42690中⽂: https://blog.wu-boy.com/2017/04/5-reasons-why-we-switched-from-python-to-go/
From Python to Go: migrating our entire APIhttps://blog.repustate.com/migrating-entire-api-go-python/
Farewell Node.jsTJhttps://goo.gl/WVxwtb44
如何將 Go 語⾔導入團隊
學習曲線程式碼簡潔沒有物件導向團隊開發⼯具整合Coding StyleTesting ToolBenchmark Tool部署環境 (Go 1.5 Cross Compiler)降低部署時間降低測試時間重啟時間非常快,Load-Balancer 不需要 Pre-warning系統效能 (記憶體⽤量, CPU 使⽤率 …)EC2 使⽤量降低 (降低 80 ~ 85%)Response time 100ms -> 10ms
47https://talks.golang.org/2014/gocon-tokyo.slide
48https://talks.golang.org/2014/gocon-tokyo.slide
實際案例A simple notification servicehttps://github.com/appleboy/gorush/
A push notification server written in Gohttps://github.com/appleboy/gorush/
$ for i in {1..9999999}; do bat -b.N=1000 -b.C=100 POST localhost:8088/api/push notifications:[email protected]; sleep 1; done
從商業利益看 Go 程式語⾔https://blog.wu-boy.com/2017/01/business-benefits-of-go/
跨平台編譯GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o hello packageGOOS=linux GOARCH=arm CGO_ENABLED=0 go build -o hello packageGOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o hello packageGOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o hello.exe package
Portable54https://github.com/mitchellh/gox
Go 核⼼功能goroutine 和 channel
Do not communicate bysharing memory; instead, share memory bycommunicating.
如何設計單⼀ Queue解決同時寫入 DB 問題 (Transaction)
MogoDB TransactionPerform Two Phase Commits.
main func
Handle func
使⽤ sync.Mutex 解決Lock and Unlock
使⽤ Lock 及 Unlock 解決
效能分析 (使⽤ Lock)
使⽤ Channel 解決goroutine 和 channel
初始化 Channel
效能分析 (使⽤ Channel)
如何設計多個 Queue解決單⼀ Queue 效能問題
多個 Go Applicationoptimistic concurrency
optimistic concurrency使⽤ sync.Mutex 解決問題? (X)使⽤ goroutine + Channel 設計單⼀ Queue? (X)使⽤ goroutine + Channel 設計多重 Queue? (X)
Udemy 線上課程https://www.udemy.com/golang-fight/?couponCode=GOLANG-INTRO
請發問?