From 33bbe945d55ce89313485f4865422d191e59e4fb Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Sun, 16 Sep 2012 19:03:50 -0700 Subject: [PATCH] hello from http --- xx-http-client.go | 13 +++++++++++++ xx-http-server.go | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 xx-http-client.go create mode 100644 xx-http-server.go diff --git a/xx-http-client.go b/xx-http-client.go new file mode 100644 index 0000000..a2c6b39 --- /dev/null +++ b/xx-http-client.go @@ -0,0 +1,13 @@ +package main + +import ("net/http"; "io/ioutil"; "fmt") + +func main() { + resp, err := http.Get("http://127.0.0.1:5000/") + if err != nil { + panic(err) + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + fmt.Print(string(body)) +} diff --git a/xx-http-server.go b/xx-http-server.go new file mode 100644 index 0000000..da78c74 --- /dev/null +++ b/xx-http-server.go @@ -0,0 +1,13 @@ +package main + +import ("net/http"; "io") + +func hello(res http.ResponseWriter, req *http.Request) { + res.Header().Set("Content-Type", "text/plain") + io.WriteString(res, "Hello From HTTP\n") +} + +func main() { + http.HandleFunc("/", hello) + http.ListenAndServe(":5000", nil) +}