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

Build MicroServices in Golang

Bo-Yi Wu
August 20, 2016

Build MicroServices in Golang

Build MicroServices in Golang

Bo-Yi Wu

August 20, 2016
Tweet

More Decks by Bo-Yi Wu

Other Decks in Technology

Transcript

  1. Agenda •  What are Microservices? •  Why Microservices? •  Golang

    Introduction •  Golang Testing Tool •  Golang Deployment 3
  2. What are Microservices?   •  Fulfill only one task • 

    Application is a suite of small services and size •  Communicate with lightweight mechanisms, often REST •  Written in different programming languages •  Use different data storage technologies 4  
  3. Why Microservices? •  Scaling Agility •  Migrating Legacy Applications • 

    Sustainable Development Speed •  Continuous Delivery •  Independent Scalability •  Technology Freedom 5
  4. Why Choose Golang •  Performance •  Multiple core •  Concurrency

    •  Compiled && portable •  Clean syntax •  Powerful standard library •  Strong type •  Open source 9
  5. 16   How We Moved Our API From Ruby to

    Go and Saved Our Sanity
  6. Getting Started •  Workspaces •  GOPATH environment variable •  Import

    paths •  Your first program •  Your first library •  Package names •  Testing 22
  7. Workspaces •  Src – contains Go source files •  Pkg – contains

    package objects •  Bin – contains executable commands 23
  8. •  Configuration –  Yaml, JSON or INI format •  Logger

    –  Access and error log format –  write file or output to console •  Web API –  JSON or XML format •  App and System status –  Memory, go version, uptime, response time … •  Deployment / Upgrades –  Docker image or binary file 61  
  9. Gofmt formats Go programs. go list ./... | grep -v

    vendor | xargs go fmt https://golang.org/cmd/gofmt/ 80
  10. Feature •  Convert go test output to junit xml • 

    Coverage testing tool •  XML (Cobertura) export •  Linter for Go source code •  Package Management for Golang •  Testing multiple Golang package 94  
  11. Run docker command 97   docker run --rm \ -v

    $(PWD):$PROJECT_PATH \ -w=$PROJECT_PATH \ appleboy/golang-testing \ sh -c ”make install && coverage all"
  12. Go build command 109   GOOS=linux \ GOARCH=amd64 \ CGO_ENABLED=0

    \ go build \ -ldflags="-s -w -X main.Version=${v}" \ -o bin/hello go-hello
  13. 110   Prepare golang Docker image Build go file Add

    bin file to Docker image Deploy image to Docker registry
  14. 111   Prepare golang Docker image Build go file Add

    bin file to Docker image Deploy image to Docker registry
  15. 117   Prepare golang Docker image Build go file Add

    bin file to Docker image Deploy image to Docker registry
  16. 119   Prepare golang Docker image Build go file Add

    bin file to Docker image Deploy image to Docker registry
  17. 124   Prepare golang Docker image Build go file Add

    bin file to Docker image Deploy image to Docker registry docker push $(ACCOUNT)/$(IMAGE):$(tag)