February 2018
Intermediate to advanced
340 pages
9h 43m
English
package main import ( "fmt" "io/ioutil" "net/http" "net/url" "strings" ) type StringServer string func (s StringServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { req.ParseForm() fmt.Printf("Received form data: %v\n", req.Form) fmt.Printf("Received header: %v\n", req.Header) rw.Write([]byte(string(s))) } func createServer(addr string) http.Server { return http.Server{ Addr: addr, Handler: StringServer("Hello world"), } } const addr = "localhost:7070" func main() { s := createServer(addr) go s.ListenAndServe() form := url.Values{} form.Set("id", "5") form.Set("name", ...Read now
Unlock full access