Creating an HTTP Server
ListenAndServe, HandlerFunc, and ServeMux
net/http package
Go's standard library net/http provides a production-capable HTTP/1.1 and HTTP/2 server without external dependencies.
Basic server
Register a handler with http.HandleFunc and start listening with http.ListenAndServe:
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, World!")
})
log.Fatal(http.ListenAndServe(":8080", nil))All lessons in this course
- Creating an HTTP Server
- Routing and Path Parameters
- Middleware Pattern
- Graceful Shutdown