Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Creating a microservice for the 1st time with go

Creating a microservice for the 1st time with go

Henrique Vicente

May 08, 2015

More Decks by Henrique Vicente

Other Decks in Programming


  1. Go is an open source programming language that makes it

    easy to build simple, reliable, and efficient software. golang.org Robert Griesemer, Rob Pike and Ken Thompson started sketching the goals for a new language on the white board on September 21, 2007.
  2. Go is a programming language designed by Google to help

    solve Google's problems, and Google has big problems. https://talks.golang.org/2012/splash.article
  3. An attempt to combine the ease of programming of an

    interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language.
  4. Influenced by • C family (basic syntax) • Pascal /

    Modula / Oberon family (declarations, packages) • Newsqueak, Limbo (concurrency) • Unix
  5. Design • Multi-value returns • No exception handling. Pleasant error

 http://blog.golang.org/error-handling-and-go • Gourotines instead of threads • Object-oriented? Yes and no.
 No type hierarchy. Interfaces. • No pointer arithmetic for safety:
 no memory illegal address risk • Garbage collected
  6. Quality tools • go fmt • go lint • go

    vet • go test • go tool cover
  7. • Package main: executable program • Others: shared libraries •

 - don’t use relative internally
 - use the path to where the repo is published • Subpackages = subdirectories
  8. No official package manager • The designers of the language

    decided not to do it for a reason. • But what if you want to guarantee a specific package version?
 https://code.google.com/p/go-wiki/wiki/ PackageManagementTools
  9. Building • go build • You get a single binary

    by default. • gox tool to build to multiple platforms easily
 or just use https://gobuilder.me/
  10. The go way • Unused variable? • Unused import? •

 = No compiling :( … :) • Just discovered: fix it automagically :)
 Productivity += 1000 • godoc -http=:6000 to see the docs on your computer or use godoc.org
  11. $GOPATH • Go likes to have all your src, pkg,

    bin inside a $GOPATH • But don’t worry. This doesn’t matter for end users of your application, given you’re release compiled binaries.
  12. Useful packages, methods • fmt.Println(“like console.log”) • fmt.Sprintf(“%+v is %v

    old”, person, person.Age()) • flag: ./cmd -backend “https://google.com/”
 Flag: backend, value: https://google.com/ • number, err := strcov.Atoi(“2442”)
 number is 2442 (int), err is nil
  13. “Dockerifying • Docker is built in go • We’ve a

    microservice that is designed to work with default options • Why not build a docker container for it?
  14. Docker Hub Registry • Add repo for automatic building on

    Docker Hub Registry to have your package certified • You can install with
 docker pull henvic/picel • See also Dockerfile.dev