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

Web Development with Golang

Web Development with Golang

A basic primer on developing a web service with Go.
For OpenWest 2015.

Avatar for Joshua Gardner

Joshua Gardner

May 07, 2015
Tweet

More Decks by Joshua Gardner

Other Decks in Programming

Transcript

  1. WEB DEVELOPMENT WITH GOLANG GET YER GOPHERS GOING GIGGLY QUICK

    Presented on May 7th, 2015 at by . OpenWest Conference Joshua Gardner
  2. GO [GOLANG] IS GREAT Statically typed but with a duck-typed

    feel. Clear and consistent style and practices. Familiar syntax. Compiled binaries for easy deployment.
  3. WHAT YOU'LL NEED TODAY: Computer with Golang 1.4 installed. An

    editor. Some knowledge of Go language (this is not an Intro to Go course). Some kind of browser (curl will do).
  4. QUICK START DOCKER d o c k e r r

    u n ­ i t g o l a n g / b i n / b a s h TRY-IT SERVER s s h g o @ 1 0 7 . 1 7 0 . 2 5 3 . 2 0 3
  5. THE N E T / H T T P PACKAGE

    Provides basic building blocks needed to write web client and server programs.
  6. A WEB SERVER “HELLO WORLD” p a c k a

    g e m a i n i m p o r t ( " n e t / h t t p " ) t y p e H e l l o W o r l d H a n d l e r s t r u c t { } f u n c ( h * H e l l o W o r l d H a n d l e r ) S e r v e H T T P ( w h t t p . R e s p o n s e W r i t e r , r * h t t p . R e q u e s t ) { w . W r i t e ( [ ] b y t e ( " H e l l o , W o r l d ! \ n " ) ) } f u n c m a i n ( ) { h t t p . L i s t e n A n d S e r v e ( " : 3 0 0 0 " , n e w ( H e l l o W o r l d H a n d l e r ) ) }
  7. Write this file, then run: g o r u n

    h e l l o w o r l d . g o Then using curl, access this web server: c u r l h t t p : / / l o c a l h o s t : 3 0 0 0 /
  8. JUST THE FOUNDATION There are many Golang web frameworks built

    on this basic Handler interface. net/http gorilla martini negroni gocraft/web Revel Beego
  9. MORE DETAILED EXAMPLE FEATURING G O C R A F

    T / W E B http://git.io/ow15go
  10. MORE PACKAGES TO USE encoding/json html/template gorilla (all of it

    is great) golang.org/x/net/websocket bitly/go-nosq codegangsta/negroni
  11. IN CONCLUSION… Go provides a powerful and flexible interface for

    web development. Start making your web services faster and more robust with Go today!