今晚九點 |《老運維帶你用 Golang 飛》

本次公開課主題:《老運維帶你用 Golang 飛》

Outline

  • What is Golang
  • Syntax
  • Concurrent
  • Example
  • Docker
  • Useful tools

History

  • Design began in late 2007 by Google.
  • Authors:
    Rob Pike (Bell Lab & UTF-8)
    Ken Thompson (UNIX & C & Turning Award)
    Robert Griesemer (Chrome JavaScript V8)

Go Users

Google, Facebook, Github, Dropbox, Docker, CloudFlare, DigitalOcean, Baidu BFE, 許式偉…

https://github.com/golang/go/wiki/GoUsers

What is Go?

  • open source
  • concurrent
  • garbage-collected
  • efficient
  • scalable
  • simple
  • http://golang.org
  • benchmark

Declarations

  • C syntax
  • Go syntax

For more information:

  • golang.org/s/decl-syntax
  • Function syntax
  • Function on type T:
  • Method of type T (Class Method?):
  • Variable (closure) of type T:
  • Multi return

Naming

  • Simple rule:
    upper case initial letter: Name is visible to clients of package
    otherwise: name (or _Name) is not visible to clients of package
  • Applies to variables, types, functions, methods, constants, fields....
  • That Is It.

Pointers and Structs

  • Go has pointers. A pointer holds the memory address of a variable.

Reflection

圖片8.png

Garbage collection

  • In C:

Auto GC (Mark and Sweep), stop-the-world(-_-)

see more: http://adamansky.bitbucket.org/slides/gc/index.html?full#1
Problems:

  • Memory leak or Wild pointer ?

Defer

  • A defer statement defers the execution of a function until the surrounding function returns.
圖片12.png
  • Defer Stack

Concurrent

  • In C:
    process, thread, libevent

  • In Go:
    goroutine
    channel
    select
    waitGroup

Goroutine

  • A goroutine is a lightweight thread managed by the Go runtime.
  • Goroutines run in the same address space, so access to shared memory must be synchronized. The sync package provides useful primitives, although you won't need them much in Go as there are other primitives. (channel & select)
  • See more: https://tour.golang.org/concurrency/1
  • go func() {}
  • coroutine Python?

Channel

  • Channels are a typed conduit through which you can send and receive values with the channel operator, <-.

Dead lock

Buffered channel

Buffered channel (like Queue in Python, thread safe FIFO)
Sends to a buffered channel block only when the buffer is full.
Receives to block when the buffer is empty.

Select

  • The select statement lets a goroutine wait on multiple communication operations.
  • A select blocks until one of its cases can run, then it executes that case. It chooses one at random if multiple are ready.
  • The default case in a select is run if no other case is ready.

WaitGroup

Example

Docker -- A Go Project

Docker basic concept

Dockerfile

Dokcer Commands

  • Image
  • docker images
  • docker build
  • docker rmi <image name>
  • docker export
  • Container
  • docker ps -a
  • docker run/restart/start/stop <container name>
  • docker logs < container name>
  • docker exec -ti $1 bash
  • Repository
  • docker login
  • docker search
  • docker push/pull
  • https://docs.docker.com/engine/reference/commandline/

Useful tools 4 Go

  • gofmt
  • go build|run|get|test
  • godoc
  • vim + YCM

What's next?

  • Try It!
  • tour.golang.org
  • golang.org/wiki/Learn
  • golang.org/project

技術交流QQ群:426582602
加入QQ群,獲取分享直播鏈接和相關資料.
咨詢報名聯(lián)系:

QQ(1):979950755 小月
QQ(2):279312229 ada
WeChat : 1902433859 小月
WeChat : 1251743084 小單

Golang 實戰(zhàn)班第2期火熱報名進行中

招生要求:

有Linux基礎海渊,有志于使用 Go 語言做分布式系統(tǒng)編程的人員,想往系統(tǒng)架構(gòu)師方向發(fā)展的同學蔗坯。BAT 架構(gòu)師帶你一起飛阔拳。

開課時間:10月14日

課程內(nèi)容:

  • Golang入門
  • Golang程序結(jié)構(gòu)
  • Golang的基礎數(shù)據(jù)類型
  • Golang復合數(shù)據(jù)類型
  • Golang的函數(shù)
  • Golang的方法
  • Golang的接口
  • Golang的協(xié)程和Channel
  • Golang基于共享變量的并發(fā)
  • Golang包和工具

課程大綱:http://51reboot.com/course/go/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末绞吁,一起剝皮案震驚了整個濱河市朦前,隨后出現(xiàn)的幾起案子厘唾,更是在濱河造成了極大的恐慌褥符,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件抚垃,死亡現(xiàn)場離奇詭異喷楣,居然都是意外死亡,警方通過查閱死者的電腦和手機鹤树,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進店門铣焊,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人罕伯,你說我怎么就攤上這事曲伊。” “怎么了追他?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵坟募,是天一觀的道長岛蚤。 經(jīng)常有香客問我,道長婿屹,這世上最難降的妖魔是什么灭美? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮昂利,結(jié)果婚禮上届腐,老公的妹妹穿的比我還像新娘。我一直安慰自己蜂奸,他們只是感情好犁苏,可當我...
    茶點故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著扩所,像睡著了一般围详。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上祖屏,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天助赞,我揣著相機與錄音,去河邊找鬼袁勺。 笑死雹食,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的期丰。 我是一名探鬼主播群叶,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼钝荡!你這毒婦竟也來了街立?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤埠通,失蹤者是張志新(化名)和其女友劉穎赎离,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體植阴,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡蟹瘾,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了掠手。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,981評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡狸捕,死狀恐怖喷鸽,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情灸拍,我是刑警寧澤做祝,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布砾省,位于F島的核電站,受9級特大地震影響混槐,放射性物質(zhì)發(fā)生泄漏编兄。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一声登、第九天 我趴在偏房一處隱蔽的房頂上張望狠鸳。 院中可真熱鬧,春花似錦悯嗓、人聲如沸件舵。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽铅祸。三九已至,卻和暖如春合武,著一層夾襖步出監(jiān)牢的瞬間临梗,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工稼跳, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留盟庞,地道東北人。 一個月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓岂贩,卻偏偏與公主長得像茫经,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子萎津,可洞房花燭夜當晚...
    茶點故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內(nèi)容

  • 你來卸伞,我認真待你,你走锉屈,我目送你離開荤傲! 不強求,隨遇而安颈渊。彼此安好遂黍,如此而已! 愿你一切安好俊嗽。我們隨緣就好雾家!
    希雅的花園閱讀 205評論 0 0
  • 其實沒人能告訴你該怎么辦,因為沒有人是你自己绍豁,只有你才能為自己的人生負責芯咧。所謂的人生大贏家,并不在于你在哪里、做什...
    Uynahhruzuy閱讀 156評論 0 0
  • #劉洲成家暴#被各大網(wǎng)絡平臺曝光之后,那首紅極一時的“你就是我心中的棉花糖”變成了“你就是我心中的大智障”...
    漠曉星閱讀 436評論 0 4