Created
May 10, 2014 17:51
-
-
Save greggyNapalm/944cd67c952dcd8711dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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