O'Reilly logo

Go: Design Patterns for Real-World Projects by Mat Ryer, Mario Castro Contreras, Vladimir Vivien

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A web client that consumes the API

We are going to put together an ultra simple web client that consumes the capabilities and data exposed through our API, allowing users to interact with the polling system we built in the previous chapter and earlier in this chapter. Our client will be made up of three web pages:

  • An index.html page that shows all the polls
  • A view.html page that shows the results of a specific poll
  • A new.html page that allows users to create new polls

Create a new folder called web alongside the api folder and add the following content to the main.go file:

package main import ( "flag" "log" "net/http" ) func main() { var addr = flag.String("addr", ":8081", "website address") flag.Parse() mux := http.NewServeMux() mux.Handle("/", http.StripPrefix("/", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required