SlideShare a Scribd company logo
1 of 32
Download to read offline
JAVA TO GO
GOOGLE GO FÜR JAVA
ENTWICKLER
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 STATT VERERBUNG
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, " ")

}

}
Generics kommen in Go 2
MÄCHTIG
CONCURRENCY
GOROUTINE
leichtgewichtiger Thread
CHANNEL
Kanal für Nachrichten
GOROUTINE
func main() {
go HelloCongressman("Russo")
}
func HelloCongressman(name string) {
1
fmt.Println("Hello Congressman", name)
2
}
3
4
5
6
7
GOROUTINE MIT SLEEP
func main() {
go HelloCongressman("Russo")
func HelloCongressman(name string) {
1
fmt.Println("Hello Congressman", name)
2
}
3
4
5
6
7
time.Sleep(5 * time.Millisecond)
8
}
9
func main() {
go HelloCongressman("Russo")
time.Sleep(5 * time.Millisecond)
func HelloCongressman(name string) {
1
fmt.Println("Hello Congressman", name)
2
}
3
4
5
6
7
8
}
9
GOROUTINE MIT WAIT GROUP
func main() {
var waitGroup sync.WaitGroup
waitGroup.Add(1)
go func() {
HelloCongressman("Russo")
waitGroup.Done()
}()
waitGroup.Wait()
}
func HelloCongressman() {
1
fmt.Println("Hello Congressman", name)
2
}
3
4
5
6
7
8
9
10
11
12
13
GOROUTINE MIT WAIT GROUP UND DEFER
defer waitGroup.Done()
HelloCongressman("Russo")
func HelloCongressman() {
1
fmt.Println("Hello Congressman", name)
2
}
3
4
func main() {
5
var waitGroup sync.WaitGroup
6
waitGroup.Add(1)
7
go func() {
8
9
10
}()
11
waitGroup.Wait()
12
}
13
CHANNEL
money := make(chan int)
go Congressman(money)
func main() {
1
2
3
4
// Nachricht senden
5
money <- 100
6
}
7
8
func Congressman(money chan int) {
9
// Nachricht empfangen
10
amount := <-money
11
12
fmt.Println("Received", amount, "$!")
13
}
14
// Nachricht senden
money <- 100
func main() {
1
money := make(chan int)
2
go Congressman(money)
3
4
5
6
}
7
8
func Congressman(money chan int) {
9
// Nachricht empfangen
10
amount := <-money
11
12
fmt.Println("Received", amount, "$!")
13
}
14
func Congressman(money chan int) {
// Nachricht empfangen
amount := <-money
fmt.Println("Received", amount, "$!")
}
func main() {
1
money := make(chan int)
2
go Congressman(money)
3
4
// Nachricht senden
5
money <- 100
6
}
7
8
9
10
11
12
13
14
CHANNEL MIT SELECT
func Congressman(money chan int) {
select {
case amount := <-money:
fmt.Println("Received", amount, "$!")
}
}
func main() {
1
money := make(chan int)
2
go Congressman(money)
3
4
// Nachricht senden
5
money <- 100
6
}
7
8
9
10
11
12
13
14
CHANNELMIT TIMEOUT
case <-time.After(1 * time.Second):
fmt.Println("Got nothing ...!")
func main() {
1
money := make(chan int)
2
go Congressman(money)
3
4
time.Sleep(2 * time.Second)
5
}
6
7
func Congressman(money chan int) {
8
select {
9
case amount := <-money:
10
fmt.Println("Received", amount, "$!")
11
12
13
}
14
}
15
time.Sleep(2 * time.Second)
func main() {
1
money := make(chan int)
2
go Congressman(money)
3
4
5
}
6
7
func Congressman(money chan int) {
8
select {
9
case amount := <-money:
10
fmt.Println("Received", amount, "$!")
11
case <-time.After(1 * time.Second):
12
fmt.Println("Got nothing ...!")
13
}
14
}
15
time.Sleep(2 * time.Second)
select {
case amount := <-money:
fmt.Println("Received", amount, "$!")
case <-time.After(1 * time.Second):
fmt.Println("Got nothing ...!")
}
func main() {
1
money := make(chan int)
2
go Congressman(money)
3
4
5
}
6
7
func Congressman(money chan int) {
8
9
10
11
12
13
14
}
15
CONCURRENCY
mit Goroutinen und Channels
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
#
#
#
#
DEMO
JAN STAMER
Solution Architect
jan.stamer@comdirect.de

More Related Content

What's hot

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
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - FunctionCody Yun
 
Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013trexy
 
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
 
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
 
Combine vs RxSwift
Combine vs RxSwiftCombine vs RxSwift
Combine vs RxSwiftshark-sea
 
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
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2Kazuho Oku
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02nikomatsakis
 
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
 
Teaching linked lists data structures using MIDI
Teaching linked lists data structures using MIDITeaching linked lists data structures using MIDI
Teaching linked lists data structures using MIDIMark Guzdial
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorialnikomatsakis
 
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]Eleanor McHugh
 
การเขียนคำสั่งควบคุมแบบวนซ้ำ ppt
การเขียนคำสั่งควบคุมแบบวนซ้ำ pptการเขียนคำสั่งควบคุมแบบวนซ้ำ ppt
การเขียนคำสั่งควบคุมแบบวนซ้ำ pptLittle Junney
 

What's hot (20)

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
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
 
Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
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
 
Combine vs RxSwift
Combine vs RxSwiftCombine vs RxSwift
Combine vs RxSwift
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
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
 
Rust-lang
Rust-langRust-lang
Rust-lang
 
Rust
RustRust
Rust
 
Project in programming
Project in programmingProject in programming
Project in programming
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
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
 
Teaching linked lists data structures using MIDI
Teaching linked lists data structures using MIDITeaching linked lists data structures using MIDI
Teaching linked lists data structures using MIDI
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
 
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
 
Assignment6
Assignment6Assignment6
Assignment6
 
การเขียนคำสั่งควบคุมแบบวนซ้ำ ppt
การเขียนคำสั่งควบคุมแบบวนซ้ำ pptการเขียนคำสั่งควบคุมแบบวนซ้ำ ppt
การเขียนคำสั่งควบคุมแบบวนซ้ำ ppt
 

Similar to JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler

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
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptxGuy Komari
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Robert Stern
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?勇浩 赖
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionHans Höchtl
 
The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189Mahmoud Samir Fayed
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMRaveen Perera
 
Introduction to go
Introduction to goIntroduction to go
Introduction to goJaehue Jang
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust languageGines Espada
 
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
 
Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Giovanni Bechis
 
Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101Logan Campbell
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional ProgrammingHoàng Lâm Huỳnh
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfclarityvision
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 

Similar to JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler (20)

Let's golang
Let's golangLet's golang
Let's golang
 
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
 
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
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
About Go
About GoAbout Go
About Go
 
The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
 
Introduction to go
Introduction to goIntroduction to go
Introduction to go
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
 
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+
 
Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)
 
Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdf
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 

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

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
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
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
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
 

JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler

  • 1. JAVA TO GO GOOGLE GO FÜR JAVA ENTWICKLER
  • 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 STATT VERERBUNG 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, " ") } } Generics kommen in Go 2
  • 20. GOROUTINE func main() { go HelloCongressman("Russo") } func HelloCongressman(name string) { 1 fmt.Println("Hello Congressman", name) 2 } 3 4 5 6 7
  • 21. GOROUTINE MIT SLEEP func main() { go HelloCongressman("Russo") func HelloCongressman(name string) { 1 fmt.Println("Hello Congressman", name) 2 } 3 4 5 6 7 time.Sleep(5 * time.Millisecond) 8 } 9 func main() { go HelloCongressman("Russo") time.Sleep(5 * time.Millisecond) func HelloCongressman(name string) { 1 fmt.Println("Hello Congressman", name) 2 } 3 4 5 6 7 8 } 9
  • 22. GOROUTINE MIT WAIT GROUP func main() { var waitGroup sync.WaitGroup waitGroup.Add(1) go func() { HelloCongressman("Russo") waitGroup.Done() }() waitGroup.Wait() } func HelloCongressman() { 1 fmt.Println("Hello Congressman", name) 2 } 3 4 5 6 7 8 9 10 11 12 13
  • 23. GOROUTINE MIT WAIT GROUP UND DEFER defer waitGroup.Done() HelloCongressman("Russo") func HelloCongressman() { 1 fmt.Println("Hello Congressman", name) 2 } 3 4 func main() { 5 var waitGroup sync.WaitGroup 6 waitGroup.Add(1) 7 go func() { 8 9 10 }() 11 waitGroup.Wait() 12 } 13
  • 24. CHANNEL money := make(chan int) go Congressman(money) func main() { 1 2 3 4 // Nachricht senden 5 money <- 100 6 } 7 8 func Congressman(money chan int) { 9 // Nachricht empfangen 10 amount := <-money 11 12 fmt.Println("Received", amount, "$!") 13 } 14 // Nachricht senden money <- 100 func main() { 1 money := make(chan int) 2 go Congressman(money) 3 4 5 6 } 7 8 func Congressman(money chan int) { 9 // Nachricht empfangen 10 amount := <-money 11 12 fmt.Println("Received", amount, "$!") 13 } 14 func Congressman(money chan int) { // Nachricht empfangen amount := <-money fmt.Println("Received", amount, "$!") } func main() { 1 money := make(chan int) 2 go Congressman(money) 3 4 // Nachricht senden 5 money <- 100 6 } 7 8 9 10 11 12 13 14
  • 25. CHANNEL MIT SELECT func Congressman(money chan int) { select { case amount := <-money: fmt.Println("Received", amount, "$!") } } func main() { 1 money := make(chan int) 2 go Congressman(money) 3 4 // Nachricht senden 5 money <- 100 6 } 7 8 9 10 11 12 13 14
  • 26. CHANNELMIT TIMEOUT case <-time.After(1 * time.Second): fmt.Println("Got nothing ...!") func main() { 1 money := make(chan int) 2 go Congressman(money) 3 4 time.Sleep(2 * time.Second) 5 } 6 7 func Congressman(money chan int) { 8 select { 9 case amount := <-money: 10 fmt.Println("Received", amount, "$!") 11 12 13 } 14 } 15 time.Sleep(2 * time.Second) func main() { 1 money := make(chan int) 2 go Congressman(money) 3 4 5 } 6 7 func Congressman(money chan int) { 8 select { 9 case amount := <-money: 10 fmt.Println("Received", amount, "$!") 11 case <-time.After(1 * time.Second): 12 fmt.Println("Got nothing ...!") 13 } 14 } 15 time.Sleep(2 * time.Second) select { case amount := <-money: fmt.Println("Received", amount, "$!") case <-time.After(1 * time.Second): fmt.Println("Got nothing ...!") } func main() { 1 money := make(chan int) 2 go Congressman(money) 3 4 5 } 6 7 func Congressman(money chan int) { 8 9 10 11 12 13 14 } 15
  • 30. DEMO
  • 31.