in Stackoverflow Survey 2019 In front of e.g. Swift, Kotlin, and Dart 9th most loved dev tech in Stackoverflow Survey 2019 Right in front of C# Compiled to native code No dependencies, just a single file WASM support That raised my interest…
has 25 Don’t be too clever “If you must read the rest of this document to understand the behavior of your program, you are being too clever. Don't be clever.” (docs) Keep code consistent „The output of the current gofmt is what your code should look like, no ifs or buts.” (GitHub) Just because it is young? Go came out late 2009, version 2 just in design phase No, it is in the language‘s genes
easy to maintain Improve where it makes sense Don’t be too fast Avoid syntactic sugar Made for Microservices & DevOps Sweetspot Web Apps/APIs Very well suited for container-based workloads Code maintainable on the long run
go mod init github.com/rstropek/golang-samples/hello-go/modules # Look at go.mod # Add sample code to main.go: # Snippet: go, 01-module go run . # Look at go.mod again # Show folder C:\Users\r.stropek\go\pkg\mod\github.com\mbndr Old: GOPATH New: Module System Started in Go 1.11 Will be default in Go 1.13 Built from sources No binary-only packages Dependencies loaded from SCM Use go plugins for modularity https://blog.golang.org/using-go-modules
Linux set GOARCH=amd64 set GOOS=linux go build bash ./modules # Cross-compile to WASM set GOOS=js set GOARCH=wasm go build -o modules.wasm Compile into single executable Cross-compilation Including WASM https://github.com/golang/go/wiki/WebAssembly
go, 03-dockerignore # Build image based on Alpine docker build -t hello-go . docker run -t --rm hello-go # Check image size docker images hello-go # Switch to „FROM scratch“ (no RUN) and build/run again # Check image size docker images hello-go Runs very well in containers Small images