狠狠撸

狠狠撸Share a Scribd company logo
Go 語言簡介
吳柏毅 Bo-Yi Wu
https://blog.wu-boy.com/
Mediatek Engineer
DevOps
Golang, PHP, Node.js ..
Some open source
Gitea
Gin
Drone
appleboy @GitHub
appleboy @twitter
appleboy @slideshare
appleboy46 @facebook
About Me
2
2017
Google Survey Result
https://blog.golang.org/survey2017-results
Go 語言基礎簡介
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 Langley
golang.org 網站及 build dashboard
4. Docker 及 Kubernets 使用 GO
2013 年及 2014 年
Golang in China
Go 發佈週期 (半年一版)
2013/05 1.1
2013/12 1.2
2014/06 1.3
2014/12 1.4
2015/08 1.5 (Google 規定以後每半年發佈一版)
2016/02 1.6
2016/08 1.7
2017/02 1.8
2017/08 1.9
2018/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
Design in the Service of
Software Engineering
https://talks.golang.org/2012/splash.article
Go 優勢
學習曲線
開發及執行效率
由 Google 維護
部署方便
跨平台編譯
內建 Coding Style, Testing 等工具
多核心處理
誰在用 Go 語言
Go 語言基礎簡介
Go 大型專案
https://github.com/golang/go/wiki/Projects
Go 語言基礎簡介
Go 語言基礎簡介
Go 語言基礎簡介
Go 語言基礎簡介
Go 語言基礎簡介
Go 語言基礎簡介
Go 語言基礎簡介
Go 語言基礎簡介
Go 語言基礎簡介
Go 語言基礎簡介
Go 語言基礎簡介
Why Go
https://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 Go
https://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 API
https://blog.repustate.com/migrating-entire-api-go-python/
Farewell
Node.js
TJ
https://goo.gl/WVxwtb
44
如何將 Go 語言導入團隊
學習曲線
程式碼簡潔
沒有物件導向
團隊開發工具整合
Coding Style
Testing Tool
Benchmark Tool
部署環境 (Go 1.5 Cross Compiler)
降低部署時間
降低測試時間
重啟時間非常快,Load-Balancer 不需要 Pre-warning
系統效能 (記憶體用量, CPU 使用率 …)
EC2 使用量降低 (降低 80 ~ 85%)
Response time 100ms -> 10ms
47
https://talks.golang.org/2014/gocon-tokyo.slide
48
https://talks.golang.org/2014/gocon-tokyo.slide
實際案例
A simple notification service
https://github.com/appleboy/gorush/
A push notification server written in Go
https://github.com/appleboy/gorush/
$ for i in {1..9999999}; do bat -b.N=1000 -b.C=100 POST
localhost:8088/api/push
notifications:=@notification.json; 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 package
GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -o hello package
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o hello package
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o hello.exe
package
Portable
54
https://github.com/mitchellh/gox
Go 語言基礎簡介
Go 核心功能
goroutine 和 channel
Do not communicate by
sharing memory;
instead, share memory by
communicating.
如何設計單一 Queue
解決同時寫入 DB 問題 (Transaction)
MogoDB Transaction
Perform Two Phase Commits.
main func
Handle func
使用 sync.Mutex 解決
Lock and Unlock
Go 語言基礎簡介
效能分析 (使用 Lock)
使用 Channel 解決
goroutine 和 channel
初始化 Channel
Go 語言基礎簡介
Go 語言基礎簡介
效能分析 (使用 Channel)
如何設計多個 Queue
解決單一 Queue 效能问题
多個 Go Application
optimistic concurrency
optimistic concurrency
使用 sync.Mutex 解決問題? (X)
使用 goroutine + Channel 設計單一 Queue? (X)
使用 goroutine + Channel 設計多重 Queue? (X)
Udemy 線上課程
https://www.udemy.com/golang-fight/?couponCode=GOLANG-INTRO
请发问?

More Related Content

Go 語言基礎簡介

Editor's Notes

  • #7: Robert Griesemer, Rob Pike 和 Ken Thompson。Robert在开发Go之前是Google V8、Chubby和HotSpot JVM的主要贡献者;Rob主要是Unix、UTF-8、plan9的作者;Ken主要是B语言、C语言的作者(共同作者)、Unix之父. Ed 編輯器發明者, vi emcas 的起點。 Brad Fitzpatrick之前是Memcache的作者,目前主要是HTTP2的实现作者。大家可以看到这些作者都是各个领域内的顶尖高手,所以当初我相信一群牛人做出来的Go也一定够牛。
  • #9: Ian Lance Taylor是GCC的作者之一,目前负责GCC的Go实现;
  • #10: Russ Cox也是目前Go的领导者之一,他和Rob Pike一起领导Go;
  • #45: https://medium.com/@tjholowaychuk/farewell-node-js-4ba9e7f3e52b#.ytdscr9d0
  • #46: 公司內部用 Python, Node.js, PHP
  • #50: 介紹一下第一屆 gopher conf 6/29 號 星期四
  • #52: 宣傳月底 golang 講題 gorush