今晚九點(diǎn) |《老運(yùn)維帶你用 Golang 飛》

本次公開課主題:《老運(yùn)維帶你用 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

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

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

Golang 實(shí)戰(zhàn)班第2期火熱報(bào)名進(jìn)行中

招生要求:

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

開課時(shí)間:10月14日

課程內(nèi)容:

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

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • 你來(lái),我認(rèn)真待你,你走,我目送你離開! 不強(qiáng)求,隨遇而安。彼此安好,如此而已! 愿你一切安好。我們隨緣就好!
    希雅的花園閱讀 214評(píng)論 0 0
  • 其實(shí)沒人能告訴你該怎么辦,因?yàn)闆]有人是你自己,只有你才能為自己的人生負(fù)責(zé)。所謂的人生大贏家,并不在于你在哪里、做什...
    Uynahhruzuy閱讀 159評(píng)論 0 0
  • #劉洲成家暴#被各大網(wǎng)絡(luò)平臺(tái)曝光之后,那首紅極一時(shí)的“你就是我心中的棉花糖”變成了“你就是我心中的大智障”...
    漠曉星閱讀 448評(píng)論 0 4