SlideShare une entreprise Scribd logo
1  sur  38
Session G001:Come With Golang
--changzeng--
--20160120---
A.G.E.N.D.A.
1. History
2. Grammar
3. Concurrence
4. Standard Library & Tool Chain
5. Golang & C
6. Production & OpenSource Projects
7. Reference
Section 1: History
• November 10, 2009 : Became a Public Open Source Project
• March 28, 2012 : Go 1.0.0 Release
• August 18,2015 : Latest Version Go 1.5
Release History
Sponsor
Mascot : Gopher Designed By Renée French Who also design Plan9’s mascot Glenda
“Robert Griesemer, Rob Pike and Ken Thompson
started sketching the goals for a new language on the
white board on September 21, 2007. ”
--Golang FAQ
Rust1.0 Released on May 15,2015 And Latest version is Rust1.5 (How Frequently)
TEAM PLAN 9
Section 2: Grammar
Structure
• Every Go program is made up of packages. And executable should have “main” package
• “import” is just like “include” in c/c++ and “import” in python. Import other packages
• Package “fmt” has PrintXxx just like “printf” in c/c++ and “print” in python
• Function begin with “func” followed by it’s name.
• “{” should be the same line with “main()” . Think about linux style and Microsoft
• “main” takes no argument like python
Section 2: Grammar
Variables & Constants
Type
Namedeclare
variable
Only used in scope
C11 “auto”
declare Name Start with 0
Auto-Increment
Without type
declare
multiple assignment
Section 2: Grammar
Basic Types
Container Types
Pointers
Go has pointers. A pointer holds
the memory address of a variable.
• Arrays
• Slices
• Maps
Test if has
Declares a dictionary
Define and assign
Len is element’s count
Cap is max size
Section 2: Grammar
Control Flow
• If…else…
Like , statement
• switch
No while in Golang
• for
default break
no condition means TRUE
If..elseif…elseif…else
Section 2: Grammar
Function
• ordinary function
• method of struct
• closure
return typeargumentsname
return multiply
values
named return values
a method is just a function
with a receiver argument
a regular function with no change
in functionality
Methods with pointer receivers can
modify the value to which the receiver
points
Functions are values
too. They can be
passed around just
like other values
Lambda
Section 2: Grammar
Interface
An interface type is defined as a set of method signatures.
When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck
--Heim, Michael
Golang’s interface is a Duck Type interface
define a interface
implementation of interface
“i” is a interface
variable
Calling a method on an interface value executes the method of the same name on its underlying type
Thought about OOP’s Polymorphisn
Section 2: Grammar
Empty Interface & Type Switches
• empty interface
a empty interface is just like
a (void *)
• type switches
1. i.(T) T is a type get the exact type
a false when failed
2. i.(type) return the type of i.
what the real type
a interface holds?
Section 2: Grammar
defer
A defer statement defers the execution of a function until the surrounding function returns
defer is a modifier declares a function’s
invoking
should be a
invoking
Outpu
t
invoke releaseB first
then invoke releaseA
Outpu
t
calculate at
defer
Section 2: Grammar
panic … recover and error
• panic
panic is just like assert()
• recover
recover will stop panic’s crash
• try..catch..
if g() panic . defer will be invoked .
and recover will get the panic
Go programs express error state with error values. The error type is a built-in interface
Which has “Error() string” return strerror()
• error
Section 2: Grammar
OOP
• polymorphism• inheritance • encapsulation
Section 3: Concurrence
CSP
communicating sequential processes (CSP). It is a member of the family
of mathematical theories of concurrency known as process algebras,
or process calculi, based on message passing via channels.
It is More About a Methodology. Not a Implementation or a Invention.
• Goroutine : a carrier of a task
• Channel : channels to pass message
• Select : tools for channels
• sync.Xxx : assist to solve synchronized problems
Go Concurrency Patterns: Pipelines and cancellation
In each stage, the goroutines
• receive values from upstream via inbound channels
• perform some function on that data, usually producing new values
• send values downstream via outbound channels
Section 3: Concurrence
Goruntine
“go”is just like “pthread_create”
“sync.WatiGroup” is like “pthread_join” or “pthread_cond_wait”
But goroutine is not a thread or process of system level
It is like a routine or a light weight thread
Section 3: Concurrence
Channel
create a read-write
channel
close channel’s write end
return a channel
receives values from the channel
repeatedly until it is closed
“chan -” : a sent-to only channel
“- chan” : a read only channel
close will cause -
get false with “ok”
Section 3: Concurrence
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.
Section 3: Concurrence
Example
No more callback, No more context
Section 3: Concurrence
Benchmark
SNG's IO/CPU Benchmark
The Computer Language Benchmarks Game
Summary
• Golang is similar to C in IO and Simple CPU based Scenes situation
• Compute-intensive situation shouldn’t be Golang’s advantage
Section 3: Concurrence
GC
Golang Compile
Golang Runtime
Section 3: Concurrence
GC
garbage collector is a concurrent, tri-color, mark-
sweep collector, an idea first proposed by Dijkstra in 1978
Go is building a garbage collector (GC) not only for 2015 but for 2025 and beyond: A GC that 
supports today’s software development and scales along with new software and hardware 
throughout the next decade. 
--Golang Blog
Result:
• Not a STW(Stop the World) GC ( = Golang1.4)
• GC in 10ms
• 85% less than before (=Golang1.4)
Principle:
• Believe golang’s team. Golang1.5 1.6 and more
• Write golang with a Cer mind. Maybe you don’t need string pkg
• Write GC friendly codes
Section 4: Standard Library  Tool Chain
Standard Library
Section 4: Standard Library  Tool Chain
IDE
• vim
• emacs
Section 4: Standard Library  Tool Chain
IDE
• atom • sublime
• eclipse• IntelliJ IDEA
• LITE
Section 4: Standard Library  Tool Chain
GoDoc
Section 4: Standard Library  Tool Chain
GoFmt
Section 4: Standard Library  Tool Chain
GoVet
GoLint
Section 4: Standard Library  Tool Chain
GoTest
ppt.go
ppt_test.go
2G/sec 
0.54ns/count
Section 5: Golang  C
Invoke C function from Golang
Section 5: Golang  C
Write CGo in *.go
Section 5: Golang  C
Invoke C funciton from a *.a
Section 5: Golang  C
Invoke C funciton from a *.so
Section 5: Golang  C
Invoke C funciton from a *.so
Section 6: Production  OpenSource Projects
Production
How is Go used at Google?
Go at Google
Section 6: Production  OpenSource Projects
OpenSource Projects
Section 6: Production  OpenSource Projects
OpenSource Projects
Zookeeper(ZAB/Paxos)
K-V Story And Service Discovery (Raft)
Distributed Messaging Platform (Message Queue)
RabbitMQ/Kafak/ZeroMQ/Nanomsg
Web Framework
Djanngo/Tornado/Webpy
Jfinal SSH
Laravel/Flight/Yii
Microservices Framework
Section 7: Reference
a. A Tour of Go
b. Effective Go
c. Package Documentation
d. Language Specification
e. The Go Memory Model
f. The Go Blog
g. Go by Example
h. 《 The Go Programming Language 》
i. 《 Go In Action 》
j. 《 Mastering Concurrency in Go 》
Example Code is [HERE]
Q  A …
The End
Thanks…

Contenu connexe

Tendances

Golang from Scala developer’s perspective
Golang from Scala developer’s perspectiveGolang from Scala developer’s perspective
Golang from Scala developer’s perspectiveSveta Bozhko
 
Developing Cross Platform Applications with Golang
Developing Cross Platform Applications with GolangDeveloping Cross Platform Applications with Golang
Developing Cross Platform Applications with GolangErhan Yakut
 
Go language presentation
Go language presentationGo language presentation
Go language presentationparamisoft
 
welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?sangam biradar
 
Golang Channels use cases
Golang Channels use casesGolang Channels use cases
Golang Channels use casesErhan Yakut
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about goDvir Volk
 
Why you should care about Go (Golang)
Why you should care about Go (Golang)Why you should care about Go (Golang)
Why you should care about Go (Golang)Aaron Schlesinger
 
An introduction to go programming language
An introduction to go programming languageAn introduction to go programming language
An introduction to go programming languageTechnology Parser
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCTim Burks
 
Understanding how concurrency work in os
Understanding how concurrency work in osUnderstanding how concurrency work in os
Understanding how concurrency work in osGenchiLu1
 
The Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventureThe Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventuremylittleadventure
 
Go Programming Language by Google
Go Programming Language by GoogleGo Programming Language by Google
Go Programming Language by GoogleUttam Gandhi
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introductionyangwm
 
A gentle intro to Golang and the Go-universe
A gentle intro to Golang and the Go-universeA gentle intro to Golang and the Go-universe
A gentle intro to Golang and the Go-universeAlex-P. Natsios
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotTsai Tsung-Yi
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationTim Burks
 
Refactoring a go project
Refactoring a go projectRefactoring a go project
Refactoring a go projectDan Tran
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaDILo Surabaya
 

Tendances (20)

Golang from Scala developer’s perspective
Golang from Scala developer’s perspectiveGolang from Scala developer’s perspective
Golang from Scala developer’s perspective
 
Optimizing and Profiling Golang Rest Api
Optimizing and Profiling Golang Rest ApiOptimizing and Profiling Golang Rest Api
Optimizing and Profiling Golang Rest Api
 
Golang online course
Golang online courseGolang online course
Golang online course
 
Developing Cross Platform Applications with Golang
Developing Cross Platform Applications with GolangDeveloping Cross Platform Applications with Golang
Developing Cross Platform Applications with Golang
 
Go language presentation
Go language presentationGo language presentation
Go language presentation
 
welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?
 
Golang Channels use cases
Golang Channels use casesGolang Channels use cases
Golang Channels use cases
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
 
Why you should care about Go (Golang)
Why you should care about Go (Golang)Why you should care about Go (Golang)
Why you should care about Go (Golang)
 
An introduction to go programming language
An introduction to go programming languageAn introduction to go programming language
An introduction to go programming language
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPC
 
Understanding how concurrency work in os
Understanding how concurrency work in osUnderstanding how concurrency work in os
Understanding how concurrency work in os
 
The Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventureThe Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventure
 
Go Programming Language by Google
Go Programming Language by GoogleGo Programming Language by Google
Go Programming Language by Google
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introduction
 
A gentle intro to Golang and the Go-universe
A gentle intro to Golang and the Go-universeA gentle intro to Golang and the Go-universe
A gentle intro to Golang and the Go-universe
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobot
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code Generation
 
Refactoring a go project
Refactoring a go projectRefactoring a go project
Refactoring a go project
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
 

En vedette

Golang server design pattern
Golang server design patternGolang server design pattern
Golang server design pattern理 傅
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 
Go for statistical programming
Go for statistical programmingGo for statistical programming
Go for statistical programmingHakka Labs
 
Simplifying open stack and kubernetes networking with romana
Simplifying open stack and kubernetes networking with romanaSimplifying open stack and kubernetes networking with romana
Simplifying open stack and kubernetes networking with romanaJuergen Brendel
 
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...Arc & Codementor
 
Container Networking Challenges for Production Readiness
Container Networking Challenges for Production ReadinessContainer Networking Challenges for Production Readiness
Container Networking Challenges for Production ReadinessVipin Jain
 
DockerCon US 2016 - Docker Networking deep dive
DockerCon US 2016 - Docker Networking deep diveDockerCon US 2016 - Docker Networking deep dive
DockerCon US 2016 - Docker Networking deep diveMadhu Venugopal
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceBo-Yi Wu
 
Git Flow and JavaScript Coding Style
Git Flow and JavaScript Coding StyleGit Flow and JavaScript Coding Style
Git Flow and JavaScript Coding StyleBo-Yi Wu
 
Docker meetup oct14
Docker meetup   oct14Docker meetup   oct14
Docker meetup oct14Vipin Jain
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in phpBo-Yi Wu
 
Phpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterPhpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterBo-Yi Wu
 
Evolving Virtual Networking with IO Visor [OpenStack Summit Austin | April 2016]
Evolving Virtual Networking with IO Visor [OpenStack Summit Austin | April 2016]Evolving Virtual Networking with IO Visor [OpenStack Summit Austin | April 2016]
Evolving Virtual Networking with IO Visor [OpenStack Summit Austin | April 2016]IO Visor Project
 
Container Networking Meetup March 31 2016
Container Networking Meetup March 31 2016Container Networking Meetup March 31 2016
Container Networking Meetup March 31 2016Andrew Randall
 
Jenkins vs gogs
Jenkins vs gogsJenkins vs gogs
Jenkins vs gogsAaron King
 
JSONSchema with golang
JSONSchema with golangJSONSchema with golang
JSONSchema with golangSuraj Deshmukh
 
The internet of things in now , see how golang is a part of this evolution
The internet of things in now , see how golang is a part of this evolutionThe internet of things in now , see how golang is a part of this evolution
The internet of things in now , see how golang is a part of this evolutionYoni Davidson
 

En vedette (20)

Golang server design pattern
Golang server design patternGolang server design pattern
Golang server design pattern
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Go for statistical programming
Go for statistical programmingGo for statistical programming
Go for statistical programming
 
Simplifying open stack and kubernetes networking with romana
Simplifying open stack and kubernetes networking with romanaSimplifying open stack and kubernetes networking with romana
Simplifying open stack and kubernetes networking with romana
 
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
 
Container Networking Challenges for Production Readiness
Container Networking Challenges for Production ReadinessContainer Networking Challenges for Production Readiness
Container Networking Challenges for Production Readiness
 
DockerCon US 2016 - Docker Networking deep dive
DockerCon US 2016 - Docker Networking deep diveDockerCon US 2016 - Docker Networking deep dive
DockerCon US 2016 - Docker Networking deep dive
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
 
Git Flow and JavaScript Coding Style
Git Flow and JavaScript Coding StyleGit Flow and JavaScript Coding Style
Git Flow and JavaScript Coding Style
 
Golang Template
Golang TemplateGolang Template
Golang Template
 
Cloud Native SDN
Cloud Native SDNCloud Native SDN
Cloud Native SDN
 
Docker meetup oct14
Docker meetup   oct14Docker meetup   oct14
Docker meetup oct14
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in php
 
Phpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterPhpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniter
 
Go 1.8 Release Party
Go 1.8 Release PartyGo 1.8 Release Party
Go 1.8 Release Party
 
Evolving Virtual Networking with IO Visor [OpenStack Summit Austin | April 2016]
Evolving Virtual Networking with IO Visor [OpenStack Summit Austin | April 2016]Evolving Virtual Networking with IO Visor [OpenStack Summit Austin | April 2016]
Evolving Virtual Networking with IO Visor [OpenStack Summit Austin | April 2016]
 
Container Networking Meetup March 31 2016
Container Networking Meetup March 31 2016Container Networking Meetup March 31 2016
Container Networking Meetup March 31 2016
 
Jenkins vs gogs
Jenkins vs gogsJenkins vs gogs
Jenkins vs gogs
 
JSONSchema with golang
JSONSchema with golangJSONSchema with golang
JSONSchema with golang
 
The internet of things in now , see how golang is a part of this evolution
The internet of things in now , see how golang is a part of this evolutionThe internet of things in now , see how golang is a part of this evolution
The internet of things in now , see how golang is a part of this evolution
 

Similaire à Come With Golang

Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golangBasil N G
 
The GO programming language
The GO programming languageThe GO programming language
The GO programming languageMarco Sabatini
 
Rootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift ApplicationsRootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift Applicationseightbit
 
Go & multi platform GUI Trials and Errors
Go & multi platform GUI Trials and ErrorsGo & multi platform GUI Trials and Errors
Go & multi platform GUI Trials and ErrorsYoshiki Shibukawa
 
The Ring programming language version 1.5.4 book - Part 11 of 185
The Ring programming language version 1.5.4 book - Part 11 of 185The Ring programming language version 1.5.4 book - Part 11 of 185
The Ring programming language version 1.5.4 book - Part 11 of 185Mahmoud Samir Fayed
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to GoSimon Hewitt
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP PerspectiveBarry Jones
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016maiktoepfer
 
Introduction to c first week slides
Introduction to c first week slidesIntroduction to c first week slides
Introduction to c first week slidesluqman bawany
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)goccy
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applicationseightbit
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IDUSPviz
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1Ahmet Bulut
 
The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.5.2 book - Part 176 of 181The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.5.2 book - Part 176 of 181Mahmoud Samir Fayed
 

Similaire à Come With Golang (20)

Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golang
 
The GO programming language
The GO programming languageThe GO programming language
The GO programming language
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Golang
GolangGolang
Golang
 
Golang
GolangGolang
Golang
 
Rootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift ApplicationsRootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift Applications
 
Go & multi platform GUI Trials and Errors
Go & multi platform GUI Trials and ErrorsGo & multi platform GUI Trials and Errors
Go & multi platform GUI Trials and Errors
 
The Ring programming language version 1.5.4 book - Part 11 of 185
The Ring programming language version 1.5.4 book - Part 11 of 185The Ring programming language version 1.5.4 book - Part 11 of 185
The Ring programming language version 1.5.4 book - Part 11 of 185
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016
 
Introduction to c first week slides
Introduction to c first week slidesIntroduction to c first week slides
Introduction to c first week slides
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part I
 
2CPP02 - C++ Primer
2CPP02 - C++ Primer2CPP02 - C++ Primer
2CPP02 - C++ Primer
 
Go at Skroutz
Go at SkroutzGo at Skroutz
Go at Skroutz
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
 
The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.5.2 book - Part 176 of 181The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.5.2 book - Part 176 of 181
 

Dernier

Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsPriya Reddy
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制pxcywzqs
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfJOHNBEBONYAP1
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...kajalverma014
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Roommeghakumariji156
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsMonica Sydney
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.krishnachandrapal52
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasDigicorns Technologies
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理F
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理F
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样ayvbos
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiMonica Sydney
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...kumargunjan9515
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdfMatthew Sinclair
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 

Dernier (20)

Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 

Come With Golang

  • 1. Session G001:Come With Golang --changzeng-- --20160120---
  • 2. A.G.E.N.D.A. 1. History 2. Grammar 3. Concurrence 4. Standard Library & Tool Chain 5. Golang & C 6. Production & OpenSource Projects 7. Reference
  • 3. Section 1: History • November 10, 2009 : Became a Public Open Source Project • March 28, 2012 : Go 1.0.0 Release • August 18,2015 : Latest Version Go 1.5 Release History Sponsor Mascot : Gopher Designed By Renée French Who also design Plan9’s mascot Glenda “Robert Griesemer, Rob Pike and Ken Thompson started sketching the goals for a new language on the white board on September 21, 2007. ” --Golang FAQ Rust1.0 Released on May 15,2015 And Latest version is Rust1.5 (How Frequently) TEAM PLAN 9
  • 4. Section 2: Grammar Structure • Every Go program is made up of packages. And executable should have “main” package • “import” is just like “include” in c/c++ and “import” in python. Import other packages • Package “fmt” has PrintXxx just like “printf” in c/c++ and “print” in python • Function begin with “func” followed by it’s name. • “{” should be the same line with “main()” . Think about linux style and Microsoft • “main” takes no argument like python
  • 5. Section 2: Grammar Variables & Constants Type Namedeclare variable Only used in scope C11 “auto” declare Name Start with 0 Auto-Increment Without type declare multiple assignment
  • 6. Section 2: Grammar Basic Types Container Types Pointers Go has pointers. A pointer holds the memory address of a variable. • Arrays • Slices • Maps Test if has Declares a dictionary Define and assign Len is element’s count Cap is max size
  • 7. Section 2: Grammar Control Flow • If…else… Like , statement • switch No while in Golang • for default break no condition means TRUE If..elseif…elseif…else
  • 8. Section 2: Grammar Function • ordinary function • method of struct • closure return typeargumentsname return multiply values named return values a method is just a function with a receiver argument a regular function with no change in functionality Methods with pointer receivers can modify the value to which the receiver points Functions are values too. They can be passed around just like other values Lambda
  • 9. Section 2: Grammar Interface An interface type is defined as a set of method signatures. When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck --Heim, Michael Golang’s interface is a Duck Type interface define a interface implementation of interface “i” is a interface variable Calling a method on an interface value executes the method of the same name on its underlying type Thought about OOP’s Polymorphisn
  • 10. Section 2: Grammar Empty Interface & Type Switches • empty interface a empty interface is just like a (void *) • type switches 1. i.(T) T is a type get the exact type a false when failed 2. i.(type) return the type of i. what the real type a interface holds?
  • 11. Section 2: Grammar defer A defer statement defers the execution of a function until the surrounding function returns defer is a modifier declares a function’s invoking should be a invoking Outpu t invoke releaseB first then invoke releaseA Outpu t calculate at defer
  • 12. Section 2: Grammar panic … recover and error • panic panic is just like assert() • recover recover will stop panic’s crash • try..catch.. if g() panic . defer will be invoked . and recover will get the panic Go programs express error state with error values. The error type is a built-in interface Which has “Error() string” return strerror() • error
  • 13. Section 2: Grammar OOP • polymorphism• inheritance • encapsulation
  • 14. Section 3: Concurrence CSP communicating sequential processes (CSP). It is a member of the family of mathematical theories of concurrency known as process algebras, or process calculi, based on message passing via channels. It is More About a Methodology. Not a Implementation or a Invention. • Goroutine : a carrier of a task • Channel : channels to pass message • Select : tools for channels • sync.Xxx : assist to solve synchronized problems Go Concurrency Patterns: Pipelines and cancellation In each stage, the goroutines • receive values from upstream via inbound channels • perform some function on that data, usually producing new values • send values downstream via outbound channels
  • 15. Section 3: Concurrence Goruntine “go”is just like “pthread_create” “sync.WatiGroup” is like “pthread_join” or “pthread_cond_wait” But goroutine is not a thread or process of system level It is like a routine or a light weight thread
  • 16. Section 3: Concurrence Channel create a read-write channel close channel’s write end return a channel receives values from the channel repeatedly until it is closed “chan -” : a sent-to only channel “- chan” : a read only channel close will cause - get false with “ok”
  • 17. Section 3: Concurrence 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.
  • 18. Section 3: Concurrence Example No more callback, No more context
  • 19. Section 3: Concurrence Benchmark SNG's IO/CPU Benchmark The Computer Language Benchmarks Game Summary • Golang is similar to C in IO and Simple CPU based Scenes situation • Compute-intensive situation shouldn’t be Golang’s advantage
  • 20. Section 3: Concurrence GC Golang Compile Golang Runtime
  • 21. Section 3: Concurrence GC garbage collector is a concurrent, tri-color, mark- sweep collector, an idea first proposed by Dijkstra in 1978 Go is building a garbage collector (GC) not only for 2015 but for 2025 and beyond: A GC that  supports today’s software development and scales along with new software and hardware  throughout the next decade.  --Golang Blog Result: • Not a STW(Stop the World) GC ( = Golang1.4) • GC in 10ms • 85% less than before (=Golang1.4) Principle: • Believe golang’s team. Golang1.5 1.6 and more • Write golang with a Cer mind. Maybe you don’t need string pkg • Write GC friendly codes
  • 22. Section 4: Standard Library Tool Chain Standard Library
  • 23. Section 4: Standard Library Tool Chain IDE • vim • emacs
  • 24. Section 4: Standard Library Tool Chain IDE • atom • sublime • eclipse• IntelliJ IDEA • LITE
  • 25. Section 4: Standard Library Tool Chain GoDoc
  • 26. Section 4: Standard Library Tool Chain GoFmt
  • 27. Section 4: Standard Library Tool Chain GoVet GoLint
  • 28. Section 4: Standard Library Tool Chain GoTest ppt.go ppt_test.go 2G/sec  0.54ns/count
  • 29. Section 5: Golang C Invoke C function from Golang
  • 30. Section 5: Golang C Write CGo in *.go
  • 31. Section 5: Golang C Invoke C funciton from a *.a
  • 32. Section 5: Golang C Invoke C funciton from a *.so
  • 33. Section 5: Golang C Invoke C funciton from a *.so
  • 34. Section 6: Production OpenSource Projects Production How is Go used at Google? Go at Google
  • 35. Section 6: Production OpenSource Projects OpenSource Projects
  • 36. Section 6: Production OpenSource Projects OpenSource Projects Zookeeper(ZAB/Paxos) K-V Story And Service Discovery (Raft) Distributed Messaging Platform (Message Queue) RabbitMQ/Kafak/ZeroMQ/Nanomsg Web Framework Djanngo/Tornado/Webpy Jfinal SSH Laravel/Flight/Yii Microservices Framework
  • 37. Section 7: Reference a. A Tour of Go b. Effective Go c. Package Documentation d. Language Specification e. The Go Memory Model f. The Go Blog g. Go by Example h. 《 The Go Programming Language 》 i. 《 Go In Action 》 j. 《 Mastering Concurrency in Go 》 Example Code is [HERE]
  • 38. Q A … The End Thanks…