From 28962d2d44548805a0c540a79c5656241986ec95 Mon Sep 17 00:00:00 2001 From: Meutel Date: Wed, 12 Jul 2017 18:37:41 +0200 Subject: [PATCH] Http server --- .gitignore | 1 + example-httpserver/main.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 example-httpserver/main.go diff --git a/.gitignore b/.gitignore index b67c4dc..6871f5f 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ example-redis/example-redis echorot13/echorot13 chatserver/chatserver example-httptcp/example-httptcp +example-httpserver/example-httpserver diff --git a/example-httpserver/main.go b/example-httpserver/main.go new file mode 100644 index 0000000..a899b2b --- /dev/null +++ b/example-httpserver/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "io" + "log" + "net/http" +) + +type MyHandler int + +func (MyHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { + resp.Header().Set("Content-Type", "text/plain") + io.WriteString(resp, req.URL.Path) +} + +func main() { + var myHandler = new(MyHandler) + s := &http.Server{ + Addr: ":9000", + Handler: myHandler, + } + log.Fatal(s.ListenAndServe()) +}