SlideShare a Scribd company logo
1 of 30
Download to read offline
EINSTIEG IN GO
STANDARD-LIBRARY UND
ÖKOSYSTEM
467.882 ZEILEN CODE
2.130 CONTRIBUTORS
3 GRÜNDE FÜR GO
1 Einfach
2 Mächtig
3 Langweilig
HELLO GOPHER
package main



import "fmt"



func main() {

fmt.Println("Hello Gopher!")
}
Ausführen
go build hellogopher.go // 1. Code kompilieren

./hellogopher // 2. Binary ausführen
go run hellogopher.go // Code kompilieren und ausführen
ENTWICKLUNG
JetBrains
GoLand
Visual
Studio Code
Vim Go
5 FAKTEN ZU GO
1 statisches Typsystem
2 Garbage Collection
3 keine Vererbung
4 Concurrency eingebaut
5 native Ausführung 

Linux, Win, z/OS, 386, amd64, ARM, wasm, ...
VARIABLEN, SLICES, SCHLEIFEN
// Variable
var frank string = "Frank"
claire := "Claire"
1
2
3
4
// Array (fixe Länge)
5
namesArray := [3]string{frank, claire, "Zoe"}
6
7
// Slice (variable Länge)
8
namesSlice := make([]string, 2)
9
namesSlice[0] = frank
10
11
// Schleife
12
for i, name := range namesSlice {
13
fmt.Println("Hello " + name + "!")
14
}
15
// Array (fixe Länge)
namesArray := [3]string{frank, claire, "Zoe"}
// Variable
1
var frank string = "Frank"
2
claire := "Claire"
3
4
5
6
7
// Slice (variable Länge)
8
namesSlice := make([]string, 2)
9
namesSlice[0] = frank
10
11
// Schleife
12
for i, name := range namesSlice {
13
fmt.Println("Hello " + name + "!")
14
}
15
// Slice (variable Länge)
namesSlice := make([]string, 2)
namesSlice[0] = frank
// Variable
1
var frank string = "Frank"
2
claire := "Claire"
3
4
// Array (fixe Länge)
5
namesArray := [3]string{frank, claire, "Zoe"}
6
7
8
9
10
11
// Schleife
12
for i, name := range namesSlice {
13
fmt.Println("Hello " + name + "!")
14
}
15
// Schleife
for i, name := range namesSlice {
fmt.Println("Hello " + name + "!")
}
// Variable
1
var frank string = "Frank"
2
claire := "Claire"
3
4
// Array (fixe Länge)
5
namesArray := [3]string{frank, claire, "Zoe"}
6
7
// Slice (variable Länge)
8
namesSlice := make([]string, 2)
9
namesSlice[0] = frank
10
11
12
13
14
15
STRUCT STATT KLASSE
type Congressman struct {
Name string
}
1
2
3
4
func main() {
5
c := Congressman{Name: "Peter Russo"}
6
fmt.Println("Hello " + c.Name + "!")
7
}
8
c := Congressman{Name: "Peter Russo"}
fmt.Println("Hello " + c.Name + "!")
type Congressman struct {
1
Name string
2
}
3
4
func main() {
5
6
7
}
8
type Congressman struct {
Name string
}
func main() {
c := Congressman{Name: "Peter Russo"}
fmt.Println("Hello " + c.Name + "!")
}
1
2
3
4
5
6
7
8
FUNCTION RECEIVER STATT INSTANZMETHODE
func (c Congressman) swearOathOfOffice() {
fmt.Printf("I, %v, swear to serve the USA.", c.Name)
}
type Congressman struct {
1
Name string
2
}
3
4
5
6
7
8
func main() {
9
c := Congressman{Name: "Peter Russo"}
10
c.swearOathOfOffice();
11
}
12
func (c Congressman) swearOathOfOffice() {
fmt.Printf("I, %v, swear to serve the USA.", c.Name)
}
c := Congressman{Name: "Peter Russo"}
c.swearOathOfOffice();
type Congressman struct {
1
Name string
2
}
3
4
5
6
7
8
func main() {
9
10
11
}
12
INTERFACE
type Greeter interface {
greet()
}
1
2
3
4
func passBy(c1 Greeter, c2 Greeter)
5
c1.greet()
6
c2.greet()
7
}
8
9
func main() {
10
c := Congressman{Name: "Frank U."
11
e := Enemy{}
12
passBy(c, e)
13
}
14
func passBy(c1 Greeter, c2 Greeter)
c1.greet()
c2.greet()
}
type Greeter interface {
1
greet()
2
}
3
4
5
6
7
8
9
func main() {
10
c := Congressman{Name: "Frank U."
11
e := Enemy{}
12
passBy(c, e)
13
}
14
func main() {
c := Congressman{Name: "Frank U."
e := Enemy{}
passBy(c, e)
}
type Greeter interface {
1
greet()
2
}
3
4
func passBy(c1 Greeter, c2 Greeter)
5
c1.greet()
6
c2.greet()
7
}
8
9
10
11
12
13
14
type Greeter interface {
greet()
}
1
2
3
4
func passBy(c1 Greeter, c2 Greeter)
5
c1.greet()
6
c2.greet()
7
}
8
9
func main() {
10
c := Congressman{Name: "Frank U."
11
e := Enemy{}
12
passBy(c, e)
13
}
14
type Congressman struct {

Name string

}


func (c Congressman) greet() {

fmt.Println("Hello", c.Name)

}
type Enemy struct{}



func (e Enemy) greet() {
fmt.Println("Go to hell!") 

}
ZU EINFACH?
STRUCT EMBEDDING
type Congressman struct {
Name string
}
1
2
3
4
type President struct {
5
Congressman // Embedded
6
7
NuclearWeaponCode string
8
}
9
10
func main() {
11
p := President{NuclearWeaponCode: "123"}
12
p.Name = "Frank Underwood"
13
p.swearOathOfOffice();
14
}
15
type President struct {
Congressman // Embedded
NuclearWeaponCode string
}
type Congressman struct {
1
Name string
2
}
3
4
5
6
7
8
9
10
func main() {
11
p := President{NuclearWeaponCode: "123"}
12
p.Name = "Frank Underwood"
13
p.swearOathOfOffice();
14
}
15
p := President{NuclearWeaponCode: "123"}
p.Name = "Frank Underwood"
p.swearOathOfOffice();
type Congressman struct {
1
Name string
2
}
3
4
type President struct {
5
Congressman // Embedded
6
7
NuclearWeaponCode string
8
}
9
10
func main() {
11
12
13
14
}
15
FEHLER
// Fehler als Rückgabewert
func (c Congressman) bribe(amount float64) error {
if c.Name != "Peter Russo" {
return errors.New("Not corrupt!")
}
c.AccountBalance += amount
return nil
}
1
2
3
4
5
6
7
8
9
func main() {
10
c := Congressman{Name: "Jackie Sharp", AccountBalance: -10.0}
11
12
// Fehler behandeln
13
err := c.bribe(5000.0)
14
if err != nil {
15
fmt.Printf("%v is not bribable.", c.Name)
16
}
17
}
18
// Fehler behandeln
err := c.bribe(5000.0)
if err != nil {
fmt.Printf("%v is not bribable.", c.Name)
}
// Fehler als Rückgabewert
1
func (c Congressman) bribe(amount float64) error {
2
if c.Name != "Peter Russo" {
3
return errors.New("Not corrupt!")
4
}
5
c.AccountBalance += amount
6
return nil
7
}
8
9
func main() {
10
c := Congressman{Name: "Jackie Sharp", AccountBalance: -10.0}
11
12
13
14
15
16
17
}
18
GENERICS
func printSliceOfInts(numbers []int) {

for _, num := range numbers {

fmt.Print(num, " ")

}

}
func printSliceOfStrings(strings []string) {

for _, num := range strings {

fmt.Print(num, " ")

}

}
Kommen in Go 1.18 im Februar 2022!
MÄCHTIG
CONCURRENCY
GOROUTINE
leichtgewichtiger Thread

CHANNEL
Kanal für Nachrichten, dient der
Kommunkation
Synchronisation
von Goroutinen
GOROUTINE
func main() {
go HelloCongressman("Russo")
}
func HelloCongressman(name string) {
1
fmt.Println("Hello Congressman", name)
2
}
3
4
5
6
7
CHANNEL
// Deklarieren und Initialisieren
c := make(chan int)
1
2
3
// Nachricht über Channel senden
4
c <- 1
5
6
// Nachricht von Channel empfangen,
7
// "Pfeil" gibt Richtung des Datenfluss an
8
value = <-c
9
// Nachricht über Channel senden
c <- 1
// Deklarieren und Initialisieren
1
c := make(chan int)
2
3
4
5
6
// Nachricht von Channel empfangen,
7
// "Pfeil" gibt Richtung des Datenfluss an
8
value = <-c
9
// Nachricht von Channel empfangen,
// "Pfeil" gibt Richtung des Datenfluss an
value = <-c
// Deklarieren und Initialisieren
1
c := make(chan int)
2
3
// Nachricht über Channel senden
4
c <- 1
5
6
7
8
9
DEBATTE MIT GOROUTINEN UND CHANNELS
debate := make(chan int) // Channel deklarieren und initialisieren
func speaker(name string, debate chan int) {
1
for {
2
microphone := <-debate // Auf Mikro warten (Nachricht empfangen)
3
4
fmt.Printf("Turn %v: %v says '%v'n", microphone, name, randomAnswer())
5
time.Sleep(400 * time.Millisecond)
6
7
microphone++
8
debate <- microphone // Mikro zurückgeben (Nachricht senden)
9
}
10
}
11
12
func main() {
13
14
15
go speaker("Jackie", debate)
16
go speaker("Frank", debate)
17
18
microphone := 1
19
debate <- microphone // Mikro geben und Diskussion starten
20
time.Sleep(2 * time.Second) // Dauer der Diskussion
21
<-debate // Mikro nehmen und Diskussion beenden
22
}
23
debate := make(chan int) // Channel deklarieren und initialisieren
go speaker("Jackie", debate)
go speaker("Frank", debate)
func speaker(name string, debate chan int) {
1
for {
2
microphone := <-debate // Auf Mikro warten (Nachricht empfangen)
3
4
fmt.Printf("Turn %v: %v says '%v'n", microphone, name, randomAnswer())
5
time.Sleep(400 * time.Millisecond)
6
7
microphone++
8
debate <- microphone // Mikro zurückgeben (Nachricht senden)
9
}
10
}
11
12
func main() {
13
14
15
16
17
18
microphone := 1
19
debate <- microphone // Mikro geben und Diskussion starten
20
time.Sleep(2 * time.Second) // Dauer der Diskussion
21
<-debate // Mikro nehmen und Diskussion beenden
22
}
23
debate := make(chan int) // Channel deklarieren und initialisieren
go speaker("Jackie", debate)
go speaker("Frank", debate)
microphone := 1
debate <- microphone // Mikro geben und Diskussion starten
time.Sleep(2 * time.Second) // Dauer der Diskussion
<-debate // Mikro nehmen und Diskussion beenden
func speaker(name string, debate chan int) {
1
for {
2
microphone := <-debate // Auf Mikro warten (Nachricht empfangen)
3
4
fmt.Printf("Turn %v: %v says '%v'n", microphone, name, randomAnswer())
5
time.Sleep(400 * time.Millisecond)
6
7
microphone++
8
debate <- microphone // Mikro zurückgeben (Nachricht senden)
9
}
10
}
11
12
func main() {
13
14
15
16
17
18
19
20
21
22
}
23
func speaker(name string, debate chan int) {
for {
microphone := <-debate // Auf Mikro warten (Nachricht empfangen)
fmt.Printf("Turn %v: %v says '%v'n", microphone, name, randomAnswer())
time.Sleep(400 * time.Millisecond)
microphone++
debate <- microphone // Mikro zurückgeben (Nachricht senden)
}
}
debate := make(chan int) // Channel deklarieren und initialisieren
go speaker("Jackie", debate)
go speaker("Frank", debate)
microphone := 1
debate <- microphone // Mikro geben und Diskussion starten
time.Sleep(2 * time.Second) // Dauer der Diskussion
<-debate // Mikro nehmen und Diskussion beenden
1
2
3
4
5
6
7
8
9
10
11
12
func main() {
13
14
15
16
17
18
19
20
21
22
}
23
DEBATTE MIT GOROUTINEN UND CHANNELS
>_ go run debate.go

Turn 1: Frank says 'You liar.'

Turn 2: Jackie says 'Back off.'

Turn 3: Frank says 'Back off.'

Turn 4: Jackie says 'My point.'

Turn 5: Frank says 'You liar.'

Turn 6: Jackie says 'You're wrong.'
STANDARDBIBLIOTHEK
Tests
#
HTTP(2) Server und Router
#
JSON
#
Logging
#
EINFACH
LANGWEILIG
Variablen,
Slices,
Schleifen
Struct
#
#
  

ZU EINFACH?
Struct
Embedding
Fehler
Generics
#
#
#
  

MÄCHTIG
Interface
Goroutine
Channel
Standardbibliothe
#
#
#
#
GO LIEBT
Microservices Serverless Functions
Kommandozeilen-Tools DevOps und Cloud
COMMUNITY
# Gophers Slack
# Go Time Podcast
# Go Blog
# Twitter Gophers List
DEMO
JAN STAMER
Solution Architect
jan.stamer@comdirect.de

More Related Content

What's hot

Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184Mahmoud Samir Fayed
 
clap: Command line argument parser for Pharo
clap: Command line argument parser for Pharoclap: Command line argument parser for Pharo
clap: Command line argument parser for PharoESUG
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my dayTor Ivry
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersLin Yo-An
 
Dts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinDts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinAhmad Arif Faizin
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2Kazuho Oku
 
The Ring programming language version 1.9 book - Part 37 of 210
The Ring programming language version 1.9 book - Part 37 of 210The Ring programming language version 1.9 book - Part 37 of 210
The Ring programming language version 1.9 book - Part 37 of 210Mahmoud Samir Fayed
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and CEleanor McHugh
 
Combine vs RxSwift
Combine vs RxSwiftCombine vs RxSwift
Combine vs RxSwiftshark-sea
 
Go for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd editionGo for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd editionEleanor McHugh
 

What's hot (20)

uerj201212
uerj201212uerj201212
uerj201212
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
Email Using Plsql
Email Using PlsqlEmail Using Plsql
Email Using Plsql
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
 
clap: Command line argument parser for Pharo
clap: Command line argument parser for Pharoclap: Command line argument parser for Pharo
clap: Command line argument parser for Pharo
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
Dts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinDts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlin
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2
 
Introducing to Asynchronous Programming
Introducing to Asynchronous  ProgrammingIntroducing to Asynchronous  Programming
Introducing to Asynchronous Programming
 
The Ring programming language version 1.9 book - Part 37 of 210
The Ring programming language version 1.9 book - Part 37 of 210The Ring programming language version 1.9 book - Part 37 of 210
The Ring programming language version 1.9 book - Part 37 of 210
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
Rust
RustRust
Rust
 
ssh.isdn.test
ssh.isdn.testssh.isdn.test
ssh.isdn.test
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 
Project in programming
Project in programmingProject in programming
Project in programming
 
General Functions
General FunctionsGeneral Functions
General Functions
 
Combine vs RxSwift
Combine vs RxSwiftCombine vs RxSwift
Combine vs RxSwift
 
Assignment6
Assignment6Assignment6
Assignment6
 
Go for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd editionGo for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd edition
 

Similar to betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem

TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsAlfonso Peletier
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Yandex
 
Distributed Computing Patterns in R
Distributed Computing Patterns in RDistributed Computing Patterns in R
Distributed Computing Patterns in Rarmstrtw
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptxGuy Komari
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?勇浩 赖
 
The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinShariful Haque Robin
 
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+ConFoo
 
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189Mahmoud Samir Fayed
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionHans Höchtl
 
ood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdfood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdfaroramobiles1
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
 
Multi client
Multi clientMulti client
Multi clientganteng8
 

Similar to betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem (20)

About Go
About GoAbout Go
About Go
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
Let's golang
Let's golangLet's golang
Let's golang
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 
Distributed Computing Patterns in R
Distributed Computing Patterns in RDistributed Computing Patterns in R
Distributed Computing Patterns in R
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
 
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
 
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189
 
Mcq cpup
Mcq cpupMcq cpup
Mcq cpup
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
ood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdfood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdf
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
Having Fun Programming!
Having Fun Programming!Having Fun Programming!
Having Fun Programming!
 
Multi client
Multi clientMulti client
Multi client
 

More from Jan Stamer

JAX 2024: Go-über-den-Wolken und in der Cloud
JAX 2024: Go-über-den-Wolken und in der CloudJAX 2024: Go-über-den-Wolken und in der Cloud
JAX 2024: Go-über-den-Wolken und in der CloudJan Stamer
 
JAX 2024: Go in der Praxis einsetzen
JAX 2024: Go in der Praxis einsetzenJAX 2024: Go in der Praxis einsetzen
JAX 2024: Go in der Praxis einsetzenJan Stamer
 
W-JAX 2023: Go über den Wolken
W-JAX 2023: Go über den WolkenW-JAX 2023: Go über den Wolken
W-JAX 2023: Go über den WolkenJan Stamer
 
CloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. Java
CloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. JavaCloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. Java
CloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. JavaJan Stamer
 
entwickler.de 05/2023: Go über den Wolken
entwickler.de 05/2023: Go über den Wolkenentwickler.de 05/2023: Go über den Wolken
entwickler.de 05/2023: Go über den WolkenJan Stamer
 
IT-Tage 2021: Java to Go - Google Go für Java-Entwickler
IT-Tage 2021: Java to Go - Google Go für Java-Entwickler IT-Tage 2021: Java to Go - Google Go für Java-Entwickler
IT-Tage 2021: Java to Go - Google Go für Java-Entwickler Jan Stamer
 
JCON 2021: Turbo powered Web Apps
JCON 2021: Turbo powered Web AppsJCON 2021: Turbo powered Web Apps
JCON 2021: Turbo powered Web AppsJan Stamer
 
Karlsruher Entwicklertag 2021: Turbo powered Web Apps
Karlsruher Entwicklertag 2021: Turbo powered Web AppsKarlsruher Entwicklertag 2021: Turbo powered Web Apps
Karlsruher Entwicklertag 2021: Turbo powered Web AppsJan Stamer
 
Jugs HH: Elefant unter Strom - von OldSQL über NoSQL zu NewSQL?
Jugs HH: Elefant unter Strom - von OldSQL über NoSQL zu NewSQL?Jugs HH: Elefant unter Strom - von OldSQL über NoSQL zu NewSQL?
Jugs HH: Elefant unter Strom - von OldSQL über NoSQL zu NewSQL?Jan Stamer
 

More from Jan Stamer (9)

JAX 2024: Go-über-den-Wolken und in der Cloud
JAX 2024: Go-über-den-Wolken und in der CloudJAX 2024: Go-über-den-Wolken und in der Cloud
JAX 2024: Go-über-den-Wolken und in der Cloud
 
JAX 2024: Go in der Praxis einsetzen
JAX 2024: Go in der Praxis einsetzenJAX 2024: Go in der Praxis einsetzen
JAX 2024: Go in der Praxis einsetzen
 
W-JAX 2023: Go über den Wolken
W-JAX 2023: Go über den WolkenW-JAX 2023: Go über den Wolken
W-JAX 2023: Go über den Wolken
 
CloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. Java
CloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. JavaCloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. Java
CloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. Java
 
entwickler.de 05/2023: Go über den Wolken
entwickler.de 05/2023: Go über den Wolkenentwickler.de 05/2023: Go über den Wolken
entwickler.de 05/2023: Go über den Wolken
 
IT-Tage 2021: Java to Go - Google Go für Java-Entwickler
IT-Tage 2021: Java to Go - Google Go für Java-Entwickler IT-Tage 2021: Java to Go - Google Go für Java-Entwickler
IT-Tage 2021: Java to Go - Google Go für Java-Entwickler
 
JCON 2021: Turbo powered Web Apps
JCON 2021: Turbo powered Web AppsJCON 2021: Turbo powered Web Apps
JCON 2021: Turbo powered Web Apps
 
Karlsruher Entwicklertag 2021: Turbo powered Web Apps
Karlsruher Entwicklertag 2021: Turbo powered Web AppsKarlsruher Entwicklertag 2021: Turbo powered Web Apps
Karlsruher Entwicklertag 2021: Turbo powered Web Apps
 
Jugs HH: Elefant unter Strom - von OldSQL über NoSQL zu NewSQL?
Jugs HH: Elefant unter Strom - von OldSQL über NoSQL zu NewSQL?Jugs HH: Elefant unter Strom - von OldSQL über NoSQL zu NewSQL?
Jugs HH: Elefant unter Strom - von OldSQL über NoSQL zu NewSQL?
 

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem

  • 2.
  • 4.
  • 5. 3 GRÜNDE FÜR GO 1 Einfach 2 Mächtig 3 Langweilig
  • 6.
  • 7. HELLO GOPHER package main import "fmt" func main() { fmt.Println("Hello Gopher!") } Ausführen go build hellogopher.go // 1. Code kompilieren ./hellogopher // 2. Binary ausführen go run hellogopher.go // Code kompilieren und ausführen
  • 9. 5 FAKTEN ZU GO 1 statisches Typsystem 2 Garbage Collection 3 keine Vererbung 4 Concurrency eingebaut 5 native Ausführung Linux, Win, z/OS, 386, amd64, ARM, wasm, ...
  • 10. VARIABLEN, SLICES, SCHLEIFEN // Variable var frank string = "Frank" claire := "Claire" 1 2 3 4 // Array (fixe Länge) 5 namesArray := [3]string{frank, claire, "Zoe"} 6 7 // Slice (variable Länge) 8 namesSlice := make([]string, 2) 9 namesSlice[0] = frank 10 11 // Schleife 12 for i, name := range namesSlice { 13 fmt.Println("Hello " + name + "!") 14 } 15 // Array (fixe Länge) namesArray := [3]string{frank, claire, "Zoe"} // Variable 1 var frank string = "Frank" 2 claire := "Claire" 3 4 5 6 7 // Slice (variable Länge) 8 namesSlice := make([]string, 2) 9 namesSlice[0] = frank 10 11 // Schleife 12 for i, name := range namesSlice { 13 fmt.Println("Hello " + name + "!") 14 } 15 // Slice (variable Länge) namesSlice := make([]string, 2) namesSlice[0] = frank // Variable 1 var frank string = "Frank" 2 claire := "Claire" 3 4 // Array (fixe Länge) 5 namesArray := [3]string{frank, claire, "Zoe"} 6 7 8 9 10 11 // Schleife 12 for i, name := range namesSlice { 13 fmt.Println("Hello " + name + "!") 14 } 15 // Schleife for i, name := range namesSlice { fmt.Println("Hello " + name + "!") } // Variable 1 var frank string = "Frank" 2 claire := "Claire" 3 4 // Array (fixe Länge) 5 namesArray := [3]string{frank, claire, "Zoe"} 6 7 // Slice (variable Länge) 8 namesSlice := make([]string, 2) 9 namesSlice[0] = frank 10 11 12 13 14 15
  • 11. STRUCT STATT KLASSE type Congressman struct { Name string } 1 2 3 4 func main() { 5 c := Congressman{Name: "Peter Russo"} 6 fmt.Println("Hello " + c.Name + "!") 7 } 8 c := Congressman{Name: "Peter Russo"} fmt.Println("Hello " + c.Name + "!") type Congressman struct { 1 Name string 2 } 3 4 func main() { 5 6 7 } 8 type Congressman struct { Name string } func main() { c := Congressman{Name: "Peter Russo"} fmt.Println("Hello " + c.Name + "!") } 1 2 3 4 5 6 7 8
  • 12. FUNCTION RECEIVER STATT INSTANZMETHODE func (c Congressman) swearOathOfOffice() { fmt.Printf("I, %v, swear to serve the USA.", c.Name) } type Congressman struct { 1 Name string 2 } 3 4 5 6 7 8 func main() { 9 c := Congressman{Name: "Peter Russo"} 10 c.swearOathOfOffice(); 11 } 12 func (c Congressman) swearOathOfOffice() { fmt.Printf("I, %v, swear to serve the USA.", c.Name) } c := Congressman{Name: "Peter Russo"} c.swearOathOfOffice(); type Congressman struct { 1 Name string 2 } 3 4 5 6 7 8 func main() { 9 10 11 } 12
  • 13. INTERFACE type Greeter interface { greet() } 1 2 3 4 func passBy(c1 Greeter, c2 Greeter) 5 c1.greet() 6 c2.greet() 7 } 8 9 func main() { 10 c := Congressman{Name: "Frank U." 11 e := Enemy{} 12 passBy(c, e) 13 } 14 func passBy(c1 Greeter, c2 Greeter) c1.greet() c2.greet() } type Greeter interface { 1 greet() 2 } 3 4 5 6 7 8 9 func main() { 10 c := Congressman{Name: "Frank U." 11 e := Enemy{} 12 passBy(c, e) 13 } 14 func main() { c := Congressman{Name: "Frank U." e := Enemy{} passBy(c, e) } type Greeter interface { 1 greet() 2 } 3 4 func passBy(c1 Greeter, c2 Greeter) 5 c1.greet() 6 c2.greet() 7 } 8 9 10 11 12 13 14 type Greeter interface { greet() } 1 2 3 4 func passBy(c1 Greeter, c2 Greeter) 5 c1.greet() 6 c2.greet() 7 } 8 9 func main() { 10 c := Congressman{Name: "Frank U." 11 e := Enemy{} 12 passBy(c, e) 13 } 14 type Congressman struct { Name string } func (c Congressman) greet() { fmt.Println("Hello", c.Name) } type Enemy struct{} func (e Enemy) greet() { fmt.Println("Go to hell!") }
  • 15. STRUCT EMBEDDING type Congressman struct { Name string } 1 2 3 4 type President struct { 5 Congressman // Embedded 6 7 NuclearWeaponCode string 8 } 9 10 func main() { 11 p := President{NuclearWeaponCode: "123"} 12 p.Name = "Frank Underwood" 13 p.swearOathOfOffice(); 14 } 15 type President struct { Congressman // Embedded NuclearWeaponCode string } type Congressman struct { 1 Name string 2 } 3 4 5 6 7 8 9 10 func main() { 11 p := President{NuclearWeaponCode: "123"} 12 p.Name = "Frank Underwood" 13 p.swearOathOfOffice(); 14 } 15 p := President{NuclearWeaponCode: "123"} p.Name = "Frank Underwood" p.swearOathOfOffice(); type Congressman struct { 1 Name string 2 } 3 4 type President struct { 5 Congressman // Embedded 6 7 NuclearWeaponCode string 8 } 9 10 func main() { 11 12 13 14 } 15
  • 16. FEHLER // Fehler als Rückgabewert func (c Congressman) bribe(amount float64) error { if c.Name != "Peter Russo" { return errors.New("Not corrupt!") } c.AccountBalance += amount return nil } 1 2 3 4 5 6 7 8 9 func main() { 10 c := Congressman{Name: "Jackie Sharp", AccountBalance: -10.0} 11 12 // Fehler behandeln 13 err := c.bribe(5000.0) 14 if err != nil { 15 fmt.Printf("%v is not bribable.", c.Name) 16 } 17 } 18 // Fehler behandeln err := c.bribe(5000.0) if err != nil { fmt.Printf("%v is not bribable.", c.Name) } // Fehler als Rückgabewert 1 func (c Congressman) bribe(amount float64) error { 2 if c.Name != "Peter Russo" { 3 return errors.New("Not corrupt!") 4 } 5 c.AccountBalance += amount 6 return nil 7 } 8 9 func main() { 10 c := Congressman{Name: "Jackie Sharp", AccountBalance: -10.0} 11 12 13 14 15 16 17 } 18
  • 17. GENERICS func printSliceOfInts(numbers []int) { for _, num := range numbers { fmt.Print(num, " ") } } func printSliceOfStrings(strings []string) { for _, num := range strings { fmt.Print(num, " ") } } Kommen in Go 1.18 im Februar 2022!
  • 19. CONCURRENCY GOROUTINE leichtgewichtiger Thread CHANNEL Kanal für Nachrichten, dient der Kommunkation Synchronisation von Goroutinen
  • 20. GOROUTINE func main() { go HelloCongressman("Russo") } func HelloCongressman(name string) { 1 fmt.Println("Hello Congressman", name) 2 } 3 4 5 6 7
  • 21. CHANNEL // Deklarieren und Initialisieren c := make(chan int) 1 2 3 // Nachricht über Channel senden 4 c <- 1 5 6 // Nachricht von Channel empfangen, 7 // "Pfeil" gibt Richtung des Datenfluss an 8 value = <-c 9 // Nachricht über Channel senden c <- 1 // Deklarieren und Initialisieren 1 c := make(chan int) 2 3 4 5 6 // Nachricht von Channel empfangen, 7 // "Pfeil" gibt Richtung des Datenfluss an 8 value = <-c 9 // Nachricht von Channel empfangen, // "Pfeil" gibt Richtung des Datenfluss an value = <-c // Deklarieren und Initialisieren 1 c := make(chan int) 2 3 // Nachricht über Channel senden 4 c <- 1 5 6 7 8 9
  • 22. DEBATTE MIT GOROUTINEN UND CHANNELS debate := make(chan int) // Channel deklarieren und initialisieren func speaker(name string, debate chan int) { 1 for { 2 microphone := <-debate // Auf Mikro warten (Nachricht empfangen) 3 4 fmt.Printf("Turn %v: %v says '%v'n", microphone, name, randomAnswer()) 5 time.Sleep(400 * time.Millisecond) 6 7 microphone++ 8 debate <- microphone // Mikro zurückgeben (Nachricht senden) 9 } 10 } 11 12 func main() { 13 14 15 go speaker("Jackie", debate) 16 go speaker("Frank", debate) 17 18 microphone := 1 19 debate <- microphone // Mikro geben und Diskussion starten 20 time.Sleep(2 * time.Second) // Dauer der Diskussion 21 <-debate // Mikro nehmen und Diskussion beenden 22 } 23 debate := make(chan int) // Channel deklarieren und initialisieren go speaker("Jackie", debate) go speaker("Frank", debate) func speaker(name string, debate chan int) { 1 for { 2 microphone := <-debate // Auf Mikro warten (Nachricht empfangen) 3 4 fmt.Printf("Turn %v: %v says '%v'n", microphone, name, randomAnswer()) 5 time.Sleep(400 * time.Millisecond) 6 7 microphone++ 8 debate <- microphone // Mikro zurückgeben (Nachricht senden) 9 } 10 } 11 12 func main() { 13 14 15 16 17 18 microphone := 1 19 debate <- microphone // Mikro geben und Diskussion starten 20 time.Sleep(2 * time.Second) // Dauer der Diskussion 21 <-debate // Mikro nehmen und Diskussion beenden 22 } 23 debate := make(chan int) // Channel deklarieren und initialisieren go speaker("Jackie", debate) go speaker("Frank", debate) microphone := 1 debate <- microphone // Mikro geben und Diskussion starten time.Sleep(2 * time.Second) // Dauer der Diskussion <-debate // Mikro nehmen und Diskussion beenden func speaker(name string, debate chan int) { 1 for { 2 microphone := <-debate // Auf Mikro warten (Nachricht empfangen) 3 4 fmt.Printf("Turn %v: %v says '%v'n", microphone, name, randomAnswer()) 5 time.Sleep(400 * time.Millisecond) 6 7 microphone++ 8 debate <- microphone // Mikro zurückgeben (Nachricht senden) 9 } 10 } 11 12 func main() { 13 14 15 16 17 18 19 20 21 22 } 23 func speaker(name string, debate chan int) { for { microphone := <-debate // Auf Mikro warten (Nachricht empfangen) fmt.Printf("Turn %v: %v says '%v'n", microphone, name, randomAnswer()) time.Sleep(400 * time.Millisecond) microphone++ debate <- microphone // Mikro zurückgeben (Nachricht senden) } } debate := make(chan int) // Channel deklarieren und initialisieren go speaker("Jackie", debate) go speaker("Frank", debate) microphone := 1 debate <- microphone // Mikro geben und Diskussion starten time.Sleep(2 * time.Second) // Dauer der Diskussion <-debate // Mikro nehmen und Diskussion beenden 1 2 3 4 5 6 7 8 9 10 11 12 func main() { 13 14 15 16 17 18 19 20 21 22 } 23
  • 23. DEBATTE MIT GOROUTINEN UND CHANNELS >_ go run debate.go Turn 1: Frank says 'You liar.' Turn 2: Jackie says 'Back off.' Turn 3: Frank says 'Back off.' Turn 4: Jackie says 'My point.' Turn 5: Frank says 'You liar.' Turn 6: Jackie says 'You're wrong.'
  • 26. GO LIEBT Microservices Serverless Functions Kommandozeilen-Tools DevOps und Cloud
  • 27. COMMUNITY # Gophers Slack # Go Time Podcast # Go Blog # Twitter Gophers List
  • 28. DEMO
  • 29.