Slide 1

Slide 1 text

Rapid API Development in Go Josh Michielsen

Slide 2

Slide 2 text

About Me → Snr Software Engineer, Platform Engineering @ Condé Nast (@condenasteng) → K8s, AWS, Go → Cyclist → Photographer → Dog Lover! @jmickey_ jmichielsen jmickey mickey.dev [email protected]

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Third Party Libraries A look at some popular 3rd party libraries that make API development easier. Conclusion What Makes Go Unique? Briefly explore what makes Go different from other languages. Language Introduction A quick dive into the basics of the Go Programming Language. Web & APIs in Go Jumping right into some code, I will demo how to utilise the Go standard library to create a simple web server and API. 01 AGENDA 02 03 05 04

Slide 5

Slide 5 text

What Makes Go Unique 01

Slide 6

Slide 6 text

Features → Clear and concise syntax → Simple concurrency model → Strong built-in tooling → Compiled into a single statically linked binary → Robust standard library → Faster than Python

Slide 7

Slide 7 text

Projects That Use Go → Kubernetes → Hashicorp Toolkit → Prometheus → Docker

Slide 8

Slide 8 text

Language Introduction 02

Slide 9

Slide 9 text

package main import "fmt" func main() { friend := "DDD East Anglia" fmt.Printf("Hello, %s", friend) } Package declaration. Main pkg produces a binary. Import statements. Function declaration. Main pkg must have function main. Variable. Will infer the type based on the right side of :=. Print a string using the ‘fmt’ package.

Slide 10

Slide 10 text

Some Examples → Lets jump into VS Code and “go” though some examples. Links to these code samples and other are provided at the end of the slide deck.

Slide 11

Slide 11 text

Concurrency → “Goroutines” are lightweight threads that provide a simple concurrency primitive. → “Channels” allow for communication between Goroutines. → Goroutines are launched using the go keyword.

Slide 12

Slide 12 text

package main import ( "fmt" "time" ) func say(s string) { for i := 0; i < 5; i++ { time.Sleep(100 * time.Millisecond) fmt.Println(s) } } func main() { go say("world") say("hello") } world hello hello world world hello hello world world hello Via ‘A Tour of Go’ - https://tour.golang.org/concurrency/1 Goroutines

Slide 13

Slide 13 text

package main import "fmt" func main() { messages := make(chan string) go func() { messages <- "ping" } msg := <-messages fmt.Println(msg) } Channels Via ‘Go by Example’ - https://gobyexample.com/channels Make a channel. Channels are typed. The <- operator sends the string to the channel. Receive from the channel and assign to a variable.

Slide 14

Slide 14 text

Compilation → Go compiles code into a single binary. → Binaries can be statically linked. → Cross-platform compilation is built-in. → Supports various architectures. CGO_ENABLED=0 go build GOOS=windows go build GOARCH=arm go build http://bit.ly/go-build-values

Slide 15

Slide 15 text

Web & APIs 03

Slide 16

Slide 16 text

Examples → Simple Web Server → JSON Response → Middleware → Dynamic Routing → Gorilla Mux 3rd Party Library Link to the repo with the examples is provided at on the final slide of the presentation.

Slide 17

Slide 17 text

Third Party Libraries 05

Slide 18

Slide 18 text

Gorilla Toolkit → Toolkit of libraries that simplify web application and API development. https://www.gorillatoolkit.org/ HttpRouter → Performant & light HTTP router with QoL improvements over net/http. https://github.com/julienschmidt/httprouter Go Kit Micro → Another popular microservices “runtime”. https://github.com/micro/micro → Popular microservices framework. https://github.com/go-kit/kit

Slide 19

Slide 19 text

Conclusion 06

Slide 20

Slide 20 text

→ Go is a fast, powerful language that provides a simple and concise syntax. → Web development and API development is possible with nothing but the standard library. → Cross-platform compilation allows you to run your applications almost anywhere. → Most 3rd party libraries simply add a nicer UX over the standard HTTP implementation.

Slide 21

Slide 21 text

VSCode Go Plugin → Great Visual Studio Code Go plugin. https://marketplace.visualstudio.com/items?itemNa me=ms-vscode.Go Go by Example → Fantastic Go language tutorial with annotated code samples. https://gobyexample.com/ Go in Action How to Write Go Code → Getting started guide by the language developers/designers. https://golang.org/doc/code.html → Highly coveted Go book. https://www.manning.com/books/go-in-action

Slide 22

Slide 22 text

http://bit.ly/go-samples Thanks for Listening! @jmickey_ jmichielsen jmickey mickey.dev [email protected]