Skip to content

Instantly share code, notes, and snippets.

@greggyNapalm
Created May 10, 2014 17:51
Show Gist options
  • Save greggyNapalm/944cd67c952dcd8711dc to your computer and use it in GitHub Desktop.
Save greggyNapalm/944cd67c952dcd8711dc to your computer and use it in GitHub Desktop.
package main
import (
"io"
"time"
"strconv"
"net/http"
"fmt"
"encoding/json"
"github.com/kr/pretty"
)
func pprint(req *http.Request) {
out, err := json.Marshal(req)
if err != nil {
panic (err)
}
fmt.Println(string(out))
}
func HelloServer(c http.ResponseWriter, req *http.Request) {
//pprint(req)
fmt.Printf("%# v", pretty.Formatter(req))
result := "hello, world!\n"
c.Header().Set("Content-Type", "text/plain")
c.Header().Set("Content-Length", strconv.Itoa(len(result)))
time.Sleep(3000 * time.Millisecond)
io.WriteString(c, "hello, world!\n");
}
func main() {
http.Handle("/", http.HandlerFunc(HelloServer));
http.ListenAndServe(":8080", nil);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment