O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

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

How to do it...

  1. Open the console and create the folder chapter09/recipe12.
  2. Navigate to the directory.
  3. Create the file form.go with the following content:
        package main        import (          "fmt"          "net/http"        )        type StringServer string        func (s StringServer) ServeHTTP(rw http.ResponseWriter,                              req *http.Request) {          fmt.Printf("Prior ParseForm: %v\n", req.Form)          req.ParseForm()          fmt.Printf("Post ParseForm: %v\n", req.Form)          fmt.Println("Param1 is : " + req.Form.Get("param1"))          rw.Write([]byte(string(s)))        }        func createServer(addr string) http.Server {          return http.Server{            Addr: addr,            Handler: StringServer("Hello world"),          }        }        func main() {          s := createServer(":8080")          fmt.Println("Server is starting...")          if err := s.ListenAndServe(); err != nil {            panic(err)          }        }

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