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

Introducing Go on Google Cloud Platform

sharifsalah
November 14, 2015

Introducing Go on Google Cloud Platform

Introductory level talk on Go (GoLang). Also covers support for the language on Google Cloud Platform and App Engine in particular.

sharifsalah

November 14, 2015
Tweet

More Decks by sharifsalah

Other Decks in Programming

Transcript

  1. Agenda • Introducing Go • Why Go? • Go on

    Google Cloud Platform • Case study in Go • Resources • Q&A
  2. Anatomy of Go • Started by Google in 2007 •

    Statically typed • Garbage-collected • No type hierarchy, loosely coupled data and behaviour modelling • Powerful support for concurrency • Natively supported on App Engine
  3. Why Go? • Readable, clean syntax • Fast performance and

    fast compilation • Compile and deploy statically linked native binaries • Built in support for remote package management • Promotes code reuse and separation of concerns • Supports procedural programming • Radically distinctive object oriented model • Widely applicable to various use cases (e.g. systems, mobile, web) • Fun!
  4. package main import "fmt" var i int = 1 func

    main() { j := 2 k := "Go, Go, Go!" fmt.Println(i, j, k) } // Run in Go Playground
  5. Go commands: go fmt go test go vet go get

    google.golang.org/api/storage/v1 go build
  6. Computing with Go • Google App Engine ◦ Go supported

    as a runtime environment • Google App Engine Managed VMs ◦ Go supported as a managed runtime • Google Container Engine ◦ Run Go applications in Docker containers at scale • Google Compute Engine ◦ Run Go applications on Linux, UNIX and Windows ◦ Go supported in Google Cloud Debugger
  7. package bookshelf // book.go type Book struct { ID int64

    Title string Author string PublishedDate string ImageURL string Description string CreatedBy string CreatedByID string }
  8. package bookshelf // book.go type BookDatabase interface { ListBooks() ([]*Book,

    error) ListBooksCreatedBy(userID string) ([]*Book, error) GetBook(id int64) (*Book, error) AddBook(b *Book) (id int64, err error) DeleteBook(id int64) error UpdateBook(b *Book) error Close() }
  9. package bookshelf // db_mysql.go func (db *mysqlDB) GetBook(id int64) (*Book,

    error) { book, err := scanBook(db.get.QueryRow(id)) if err == sql.ErrNoRows { return nil, fmt.Errorf("mysql: couldn’t find book id %d", id) } if err != nil { return nil, fmt.Errorf("mysql: couldn’t get book: %v", err) } return book, nil }
  10. package bookshelf // db_mongo.go func (db *mongoDB) GetBook(id int64) (*Book,

    error) { b := &Book{} if err := db.c.Find(bson.D{{"id", id}}).One(b); err != nil { return nil, err } return b, nil }
  11. package main // app.go func bookFromRequest(r *http.Request) (*bookshelf.Book, error) {

    id, err := strconv.ParseInt(mux.Vars(r)["id"], 10, 64) if err != nil { return nil, fmt.Errorf("bad book id: %v", err) } book, err := bookshelf.DB.GetBook(id) if err != nil { return nil, fmt.Errorf("could not find book: %v", err) } return book, nil }
  12. Cloud A Cloud B migration db app db app ✓

    Abstract away storage layer ✓ Promote separation of concerns ✓ Minimise lock-in of managed services
  13. Sample projects using Go Docker: Build, ship and run containers

    on Linux https://www.docker.com/ Hugo: Static site generator https://gohugo.io/ Kubernetes: Scheduler and orchestrate Docker containers http://kubernetes.io/ Packer: Automation tool for creating machine and container images https://www.packer.io/ Vitess: Manage and scale MySQL databases http://vitess.io/
  14. Get started with Go A tour of Go https://tour.golang.org/ Get

    started with go on Google Cloud Platform https://cloud.google.com/go Codelab https://io2014codelabs.appspot.com/static/codelabs/go-codelab/#1 Tutorial https://cloud.google.com/appengine/docs/go/gettingstarted/introduction Awesome Go https://github.com/avelino/awesome-go
  15. Go tools Go binary distributions https://golang.org/ Go Playground https://play.golang.org/ Go

    App Engine SDK https://cloud.google.com/appengine/downloads Gorilla http://www.gorillatoolkit.org/
  16. Sharif Salah Google Developer Expert 2015 Google+ profile @sharif_salah Thank

    you! Any questions? The Go logo was designed by Renee French and is licensed under the Creative Commons Attribution 3.0 License.