hello from http

This commit is contained in:
Mark McGranaghan 2012-09-16 19:03:50 -07:00
parent 1c0a6d298f
commit 33bbe945d5
2 changed files with 26 additions and 0 deletions

13
xx-http-client.go Normal file
View File

@ -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))
}

13
xx-http-server.go Normal file
View File

@ -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)
}