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()) +}