ktimoney | 8ead72a | 2022-04-12 15:10:10 +0100 | [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 X509!") // 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 | } |