ktimoney | 6be0529 | 2022-03-02 12:53:14 +0000 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | ) |
| 6 | |
| 7 | // create a handler struct |
| 8 | type HttpHandler struct{} |
| 9 | |
| 10 | // implement `ServeHTTP` method on `HttpHandler` struct |
| 11 | func (h HttpHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { |
| 12 | // create response binary data |
| 13 | data := []byte("Hello World!") // slice of bytes |
| 14 | // write `data` to response |
| 15 | res.Write(data) |
| 16 | } |
| 17 | |
| 18 | func main() { |
| 19 | // create a new handler |
| 20 | handler := HttpHandler{} |
| 21 | // listen and serve |
| 22 | http.ListenAndServe(":9000", handler) |
| 23 | } |