SlideShare une entreprise Scribd logo
1  sur  29
How I built my first web 
app in Go 
16 Sep 2014 
Audrey Lim 
audreylh@gmail.com 
Twitter: @AudreyLim77
About Me 
Building Go applications
About Me 
Lawyer (1-2 yrs)
About Me 
Lawyer (1-2 yrs) 
Learning Journey 
May – Jul 2014: HTML, CSS, JS
About Me 
Lawyer (1-2 yrs) 
Learning Journey 
May – Jul 2014: HTML, CSS, JS 
(codeacademy, books, 
websites)
About Me 
Lawyer (1-2 yrs) 
Learning Journey 
(codeacademy, books, 
websites) 
May – Jul 2014: HTML, CSS, JS 
mid-Jul 2014: Go (1st backend)
About Me 
Lawyer (1-2 yrs) 
Learning Journey 
(codeacademy, books, 
websites) 
(everywhere) 
May – Jul 2014: HTML, CSS, JS 
mid-Jul 2014: Go (1st backend)
About Me 
Lawyer (1-2 yrs) 
Learning Journey 
(codeacademy, books, 
websites) 
(everywhere) 
May – Jul 2014: HTML, CSS, JS 
mid-Jul 2014: Go (1st backend) 
mid-Aug 2014: deployed 1st app – CRUD app
About Me 
Lawyer (1-2 yrs) 
Learning Journey 
(codeacademy, books, 
websites) 
(everywhere) 
May – Jul 2014: HTML, CSS, JS 
mid-Jul 2014: Go (1st backend) 
mid-Aug 2014: deployed 1st app – CRUD app 
end-Aug 2014: deployed 2nd app – API client
Go Resources 
golang.org 
Books and websites 
Sample applications 
Stackoverflow, Go-nuts mailing list
Go Resources 
golang.org (Go Tour, Docs, Go blog) 
Books and websites 
Sample applications 
Stackoverflow, Go-nuts mailing list
Go Resources 
golang.org (Go Tour, Docs, Go blog) 
Books and websites (www.golang-book.com, www.gobyexample.com) 
Sample applications 
Stackoverflow, Go-nuts mailing list
Go Resources 
golang.org (Go Tour, Docs, Go blog) 
Books and websites (www.golang-book.com, www.gobyexample.com) 
Sample applications (Go Wiki, from books) 
Stackoverflow, Go-nuts mailing list
Experience with Go
Building Go applications
CRUD App 
Simple CRUD App using MySQL 
for data persistence 
API Client 
Flickr, Weather API
1st app: CRUD App 
Sign up/Sign in 
Read Status 
Create Status 
Delete Status 
Edit Status 
Sign out 
MySQL
Basic Structure 
package main 
Import ( 
“fmt” 
“net/http” 
) 
func handler(w http.ResponseWriter, r *http.Request) { 
fmt.Fprint(w, “hello world!”) 
} 
func main() { 
http.HandleFunc(“/”, handler) 
http.ListenAndServe(“:8080”, nil) 
}
Basic Structure 
package main 
Import ( 
“fmt” 
“net/http” 
) 
All executable commands use package main 
Print output to client 
func handler(w http.ResponseWriter, r *http.Request) { 
fmt.Fprint(w, “hello world!”) 
} 
func main() { 
Handler function when root is 
requested 
http.HandleFunc(“/”, handler) 
http.ListenAndServe(“:8080”, nil) 
} 
Local server connection 
Go’s stdlib 
Entry point
Libraries 
import ( 
"database/sql" 
"html/template" 
"fmt" 
"log" 
"net/http" 
"os" 
_ "github.com/go-sql-driver/mysql" 
"github.com/gorilla/mux" 
"github.com/gorilla/securecookie” 
)
Libraries 
Standard library 
import ( 
"database/sql" 
"html/template" 
"fmt" 
"log" 
"net/http" 
"os" 
_ "github.com/go-sql-driver/mysql" 
"github.com/gorilla/mux" 
"github.com/gorilla/securecookie” 
) 
External packages
Data Structs 
Type Slice of Pointers to Post struct 
type User struct { 
Userid int64 
Username string 
Password string 
Posts []*Post 
} 
type Post struct { 
Tweetid string 
Username string 
Status string 
}
Database functions 
func ReadStatus() (res [][]string) { Return slice of slice of strings 
err := db.Ping() 
if err != nil { 
log.Fatal(err) 
} 
rows, err := db.Query("SELECT id, tweet, username FROM posts WHERE 
username = ? ORDER BY id DESC", currentuser) 
if err != nil { 
log.Fatal(err) 
} 
defer rows.Close() 
var tweet, id, username string 
for rows.Next() { 
err := rows.Scan(&id, &tweet, &username) 
if err != nil { 
return res 
} 
var a []string 
a = append(a, id, tweet, username) 
res = append(res, a) 
} 
return 
}
Database functions 
func ReadStatus() (res [][]string) { Return slice of slice of strings 
err := db.Ping() 
if err != nil { 
log.Fatal(err) 
} 
rows, err := db.Query("SELECT id, tweet, username FROM posts WHERE 
username = ? ORDER BY id DESC", currentuser) 
if err != nil { 
log.Fatal(err) 
} 
defer rows.Close() 
var tweet, id, username string 
for rows.Next() { 
err := rows.Scan(&id, &tweet, &username) 
if err != nil { 
return res 
} 
var a []string 
a = append(a, id, tweet, username) 
res = append(res, a) 
} 
return 
} 
Verify db connection 
Raw queries 
Append strings to slice 
Append slice of strings to output
Handler functions 
func homeHandler(w http.ResponseWriter, r *http.Request) { 
Create slice with Post instances 
Append slice of Post 
instances to Posts slice 
currentuser = getUserName(r) 
if currentuser != "" { 
var as []Post 
a := User{} 
m := ReadStatus() 
for i := 0; i < len(m); i++ { 
as = append(as, Post{Tweetid: m[i][0], Username: 
currentuser, Status: m[i][1]}) 
} 
a = User{Username: currentuser} 
for i := 0; i < len(m); i++ { 
a.Posts = append(a.Posts, &as[i]) 
} 
renderTemplate(w, "home", "homepage", a) 
} else { 
http.Redirect(w, r, "/", 302) 
} 
} 
Wrapper func around 
html/template library
Func main 
Open connection pool 
Handlers for URL paths 
func main() { 
db, err = sql.Open("mysql", 
os.Getenv("DB_USERNAME")+":"+os.Getenv("DB_PASSWORD")+"@tcp("+os.Getenv("DB 
_CLEARDB")+":3306)/"+os.Getenv("DB_NAME")) 
if err != nil { 
log.Fatal(err) 
} 
defer db.Close() 
router.HandleFunc("/", logHandler) 
router.HandleFunc("/login", loginHandler) 
router.HandleFunc("/home", homeHandler) 
router.HandleFunc("/home/tweets", usertweetHandler).Methods("POST") 
router.HandleFunc("/logout", logoutHandler).Methods("POST") 
router.HandleFunc("/home/delete", deleteHandler).Methods("POST") 
router.HandleFunc("/home/edit", editHandler).Methods("POST") 
router.HandleFunc("/home/save", saveHandler).Methods("POST”) 
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./layout/"))) 
http.Handle("/", router) 
err := http.ListenAndServe(":"+os.Getenv("PORT"), nil) 
if err != nil { 
panic(err) 
} 
} 
Port for server 
connection
2nd app: API Client 
Get a series of photos from Flickr 
for a random city and display 
current weather data for the same 
city
Libraries 
import ( 
"encoding/json" 
"fmt" 
"html/template" 
"io/ioutil" 
"log" 
"math/rand" 
"net/http" 
"os" 
"strconv" 
"time" 
)
Thank you. 
https://github.com/AudreyLim/weathergo 
https://github.com/AudreyLim/twittergo 
audreylh@gmail.com 
Twitter: @AudreyLim77

Contenu connexe

Tendances

Velocity tips and tricks
Velocity tips and tricksVelocity tips and tricks
Velocity tips and tricksdotCMS
 
No sql databases blrdroid devfest 2016
No sql databases   blrdroid devfest 2016No sql databases   blrdroid devfest 2016
No sql databases blrdroid devfest 2016amsanjeev
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法Tomohiro Nishimura
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-CEddie Kao
 
Class 7b: Files & File I/O
Class 7b: Files & File I/OClass 7b: Files & File I/O
Class 7b: Files & File I/OMarc Gouw
 
Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)Bruno Delb
 
Neo4j Graph Database และการประยุกตร์ใช้
Neo4j Graph Database และการประยุกตร์ใช้Neo4j Graph Database และการประยุกตร์ใช้
Neo4j Graph Database และการประยุกตร์ใช้Chakrit Phain
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup Alberto Paro
 
Ramda, a functional JavaScript library
Ramda, a functional JavaScript libraryRamda, a functional JavaScript library
Ramda, a functional JavaScript libraryDerek Willian Stavis
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJsHenri Binsztok
 
Embedding a language into string interpolator
Embedding a language into string interpolatorEmbedding a language into string interpolator
Embedding a language into string interpolatorMichael Limansky
 

Tendances (19)

Velocity tips and tricks
Velocity tips and tricksVelocity tips and tricks
Velocity tips and tricks
 
Sphinx как база данных
Sphinx как база данныхSphinx как база данных
Sphinx как база данных
 
No sql databases blrdroid devfest 2016
No sql databases   blrdroid devfest 2016No sql databases   blrdroid devfest 2016
No sql databases blrdroid devfest 2016
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
 
Grails queries
Grails   queriesGrails   queries
Grails queries
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
 
Class 7b: Files & File I/O
Class 7b: Files & File I/OClass 7b: Files & File I/O
Class 7b: Files & File I/O
 
Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)
 
Neo4j Graph Database และการประยุกตร์ใช้
Neo4j Graph Database และการประยุกตร์ใช้Neo4j Graph Database และการประยุกตร์ใช้
Neo4j Graph Database และการประยุกตร์ใช้
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
 
Ramda, a functional JavaScript library
Ramda, a functional JavaScript libraryRamda, a functional JavaScript library
Ramda, a functional JavaScript library
 
Fun with Python
Fun with PythonFun with Python
Fun with Python
 
Beautiful soup
Beautiful soupBeautiful soup
Beautiful soup
 
.Net (F # ) Records, lists
.Net (F # ) Records, lists.Net (F # ) Records, lists
.Net (F # ) Records, lists
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJs
 
Embedding a language into string interpolator
Embedding a language into string interpolatorEmbedding a language into string interpolator
Embedding a language into string interpolator
 
Learning How To Use Jquery #5
Learning How To Use Jquery #5Learning How To Use Jquery #5
Learning How To Use Jquery #5
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
One Database To Rule 'em All
One Database To Rule 'em AllOne Database To Rule 'em All
One Database To Rule 'em All
 

Similaire à Golang slidesaudrey

Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with SwagJens Ravens
 
Net/http and the http.handler interface
Net/http and the http.handler interfaceNet/http and the http.handler interface
Net/http and the http.handler interfaceJoakim Gustin
 
Net/http and the http.handler interface
Net/http and the http.handler interfaceNet/http and the http.handler interface
Net/http and the http.handler interfaceEvolve
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperJon Kruger
 
Graphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiDGraphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiDCODEiD PHP Community
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talkdtdannen
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceMaarten Balliauw
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Ngoc Dao
 
Writing RESTful web services using Node.js
Writing RESTful web services using Node.jsWriting RESTful web services using Node.js
Writing RESTful web services using Node.jsFDConf
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
From polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratchFrom polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratchSergi González Pérez
 
Developing web applications in Rust
Developing web applications in RustDeveloping web applications in Rust
Developing web applications in RustSylvain Wallez
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme SwiftMovel
 
Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013yohanbeschi
 

Similaire à Golang slidesaudrey (20)

Go react codelab
Go react codelabGo react codelab
Go react codelab
 
Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with Swag
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
Net/http and the http.handler interface
Net/http and the http.handler interfaceNet/http and the http.handler interface
Net/http and the http.handler interface
 
Net/http and the http.handler interface
Net/http and the http.handler interfaceNet/http and the http.handler interface
Net/http and the http.handler interface
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 
Symfony + GraphQL
Symfony + GraphQLSymfony + GraphQL
Symfony + GraphQL
 
Graphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiDGraphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiD
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Writing RESTful web services using Node.js
Writing RESTful web services using Node.jsWriting RESTful web services using Node.js
Writing RESTful web services using Node.js
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
From polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratchFrom polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratch
 
Developing web applications in Rust
Developing web applications in RustDeveloping web applications in Rust
Developing web applications in Rust
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013
 

Golang slidesaudrey

  • 1. How I built my first web app in Go 16 Sep 2014 Audrey Lim audreylh@gmail.com Twitter: @AudreyLim77
  • 2. About Me Building Go applications
  • 3. About Me Lawyer (1-2 yrs)
  • 4. About Me Lawyer (1-2 yrs) Learning Journey May – Jul 2014: HTML, CSS, JS
  • 5. About Me Lawyer (1-2 yrs) Learning Journey May – Jul 2014: HTML, CSS, JS (codeacademy, books, websites)
  • 6. About Me Lawyer (1-2 yrs) Learning Journey (codeacademy, books, websites) May – Jul 2014: HTML, CSS, JS mid-Jul 2014: Go (1st backend)
  • 7. About Me Lawyer (1-2 yrs) Learning Journey (codeacademy, books, websites) (everywhere) May – Jul 2014: HTML, CSS, JS mid-Jul 2014: Go (1st backend)
  • 8. About Me Lawyer (1-2 yrs) Learning Journey (codeacademy, books, websites) (everywhere) May – Jul 2014: HTML, CSS, JS mid-Jul 2014: Go (1st backend) mid-Aug 2014: deployed 1st app – CRUD app
  • 9. About Me Lawyer (1-2 yrs) Learning Journey (codeacademy, books, websites) (everywhere) May – Jul 2014: HTML, CSS, JS mid-Jul 2014: Go (1st backend) mid-Aug 2014: deployed 1st app – CRUD app end-Aug 2014: deployed 2nd app – API client
  • 10. Go Resources golang.org Books and websites Sample applications Stackoverflow, Go-nuts mailing list
  • 11. Go Resources golang.org (Go Tour, Docs, Go blog) Books and websites Sample applications Stackoverflow, Go-nuts mailing list
  • 12. Go Resources golang.org (Go Tour, Docs, Go blog) Books and websites (www.golang-book.com, www.gobyexample.com) Sample applications Stackoverflow, Go-nuts mailing list
  • 13. Go Resources golang.org (Go Tour, Docs, Go blog) Books and websites (www.golang-book.com, www.gobyexample.com) Sample applications (Go Wiki, from books) Stackoverflow, Go-nuts mailing list
  • 16. CRUD App Simple CRUD App using MySQL for data persistence API Client Flickr, Weather API
  • 17. 1st app: CRUD App Sign up/Sign in Read Status Create Status Delete Status Edit Status Sign out MySQL
  • 18. Basic Structure package main Import ( “fmt” “net/http” ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, “hello world!”) } func main() { http.HandleFunc(“/”, handler) http.ListenAndServe(“:8080”, nil) }
  • 19. Basic Structure package main Import ( “fmt” “net/http” ) All executable commands use package main Print output to client func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, “hello world!”) } func main() { Handler function when root is requested http.HandleFunc(“/”, handler) http.ListenAndServe(“:8080”, nil) } Local server connection Go’s stdlib Entry point
  • 20. Libraries import ( "database/sql" "html/template" "fmt" "log" "net/http" "os" _ "github.com/go-sql-driver/mysql" "github.com/gorilla/mux" "github.com/gorilla/securecookie” )
  • 21. Libraries Standard library import ( "database/sql" "html/template" "fmt" "log" "net/http" "os" _ "github.com/go-sql-driver/mysql" "github.com/gorilla/mux" "github.com/gorilla/securecookie” ) External packages
  • 22. Data Structs Type Slice of Pointers to Post struct type User struct { Userid int64 Username string Password string Posts []*Post } type Post struct { Tweetid string Username string Status string }
  • 23. Database functions func ReadStatus() (res [][]string) { Return slice of slice of strings err := db.Ping() if err != nil { log.Fatal(err) } rows, err := db.Query("SELECT id, tweet, username FROM posts WHERE username = ? ORDER BY id DESC", currentuser) if err != nil { log.Fatal(err) } defer rows.Close() var tweet, id, username string for rows.Next() { err := rows.Scan(&id, &tweet, &username) if err != nil { return res } var a []string a = append(a, id, tweet, username) res = append(res, a) } return }
  • 24. Database functions func ReadStatus() (res [][]string) { Return slice of slice of strings err := db.Ping() if err != nil { log.Fatal(err) } rows, err := db.Query("SELECT id, tweet, username FROM posts WHERE username = ? ORDER BY id DESC", currentuser) if err != nil { log.Fatal(err) } defer rows.Close() var tweet, id, username string for rows.Next() { err := rows.Scan(&id, &tweet, &username) if err != nil { return res } var a []string a = append(a, id, tweet, username) res = append(res, a) } return } Verify db connection Raw queries Append strings to slice Append slice of strings to output
  • 25. Handler functions func homeHandler(w http.ResponseWriter, r *http.Request) { Create slice with Post instances Append slice of Post instances to Posts slice currentuser = getUserName(r) if currentuser != "" { var as []Post a := User{} m := ReadStatus() for i := 0; i < len(m); i++ { as = append(as, Post{Tweetid: m[i][0], Username: currentuser, Status: m[i][1]}) } a = User{Username: currentuser} for i := 0; i < len(m); i++ { a.Posts = append(a.Posts, &as[i]) } renderTemplate(w, "home", "homepage", a) } else { http.Redirect(w, r, "/", 302) } } Wrapper func around html/template library
  • 26. Func main Open connection pool Handlers for URL paths func main() { db, err = sql.Open("mysql", os.Getenv("DB_USERNAME")+":"+os.Getenv("DB_PASSWORD")+"@tcp("+os.Getenv("DB _CLEARDB")+":3306)/"+os.Getenv("DB_NAME")) if err != nil { log.Fatal(err) } defer db.Close() router.HandleFunc("/", logHandler) router.HandleFunc("/login", loginHandler) router.HandleFunc("/home", homeHandler) router.HandleFunc("/home/tweets", usertweetHandler).Methods("POST") router.HandleFunc("/logout", logoutHandler).Methods("POST") router.HandleFunc("/home/delete", deleteHandler).Methods("POST") router.HandleFunc("/home/edit", editHandler).Methods("POST") router.HandleFunc("/home/save", saveHandler).Methods("POST”) router.PathPrefix("/").Handler(http.FileServer(http.Dir("./layout/"))) http.Handle("/", router) err := http.ListenAndServe(":"+os.Getenv("PORT"), nil) if err != nil { panic(err) } } Port for server connection
  • 27. 2nd app: API Client Get a series of photos from Flickr for a random city and display current weather data for the same city
  • 28. Libraries import ( "encoding/json" "fmt" "html/template" "io/ioutil" "log" "math/rand" "net/http" "os" "strconv" "time" )
  • 29. Thank you. https://github.com/AudreyLim/weathergo https://github.com/AudreyLim/twittergo audreylh@gmail.com Twitter: @AudreyLim77