SlideShare a Scribd company logo
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 184
Mahmoud Samir Fayed
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
Cody Yun
 
Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013
trexy
 
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 210
Mahmoud Samir Fayed
 
Combine vs RxSwift
Combine vs RxSwiftCombine vs RxSwift
Combine vs RxSwift
shark-sea
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2
Kazuho Oku
 
Introducing to Asynchronous Programming
Introducing to Asynchronous  ProgrammingIntroducing to Asynchronous  Programming
Introducing to Asynchronous Programming
Александр Федоров
 
Rust-lang
Rust-langRust-lang
Rust
RustRust
Project in programming
Project in programmingProject in programming
Project in programming
sahashi11342091
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
nikomatsakis
 
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
Eleanor 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 MIDI
Mark Guzdial
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
nikomatsakis
 
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
 
Assignment6
Assignment6Assignment6
Assignment6
Ryan Gogats
 
การเขียนคำสั่งควบคุมแบบวนซ้ำ 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

Let's golang
Let's golangLet's golang
Let's golang
SuHyun Jeon
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
André Faria Gomes
 
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
Alfonso Peletier
 
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
Nguyen Thi Lan Phuong
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
Wei-Ning Huang
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
Guy 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 1
Robert Stern
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
勇浩 赖
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Hans Höchtl
 
About Go
About GoAbout Go
About Go
Jongmin Kim
 
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
Mahmoud Samir Fayed
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
Raveen Perera
 
Introduction to go
Introduction to goIntroduction to go
Introduction to go
Jaehue Jang
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
Gines 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 101
Logan Campbell
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
Hoà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 .pdf
clarityvision
 
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 Cloud
Jan 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 einsetzen
Jan 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 Wolken
Jan 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. Java
Jan 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 Wolken
Jan 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 Apps
Jan 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 Apps
Jan 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

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

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.