Skip to content

Instantly share code, notes, and snippets.

@Tiliavir
Last active June 2, 2021 06:38
Show Gist options
  • Save Tiliavir/42ed0cbfbd8f7c3780362c77d188a38a to your computer and use it in GitHub Desktop.
Save Tiliavir/42ed0cbfbd8f7c3780362c77d188a38a to your computer and use it in GitHub Desktop.
First contact with Go

Go

History

  • since 2009
  • Open Source @Google
  • developed by Ken Thompson, Rob Pike, Robert Griesemer
  • mainly influenced by C, C++, C# and Java

Characteristics

  • compiled, statically typed
  • syntax similar to C / C++ / Java
  • fast compilation and execution
  • compiles to standalone executables
  • no IL / Runtime
  • concurrency support in the language (keywords)
  • garbage collector

Built with Go

  • Hugo
  • docker
  • kubernetes
  • istio
  • prometheus

Already more than 40% of Open Source Software is written in Go, according to CNCF OpenSource Software.

Hello World

Code

package main
import "fmt"

func main () {
  fmt.Println("Hello, world!")
}

Execution

IDE

  • VS Code with Go tools
  • Atom
  • GoLand (JetBrains - no Community Edition yet)
  • IntelliJ Idea

Comparison with Java

Unit Tests und Coverage in Go

  • tests are next to the code, files end with _test.go
  • there are no (built-in) asserts
  • test execution with $ go test .
  • coverage: $ go test -coverprofile=coverage.out . or go tool cover -html=coverage.out

Code Style

Go comes with its own formatter. It is best practice to follow its guidlines and run go fmt on changed files / folders, before committing.

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment