The http package in Go language
The primary role of http package
Package http provides HTTP client and server implementations.
Code Anatomy
- Get, Head, Post, and PostForm make HTTP (or HTTPS) requests.
- The client must close the response body when finished with it.
- For control over HTTP client headers, redirect policy, and other settings, create a Client;
- For control over proxies, TLS configuration, keep-alives, compression, and other settings, create a Transport.
- Clients and Transports are safe for concurrent use by multiple goroutines and for efficiency should only be created once and re-used.
- ListenAndServe starts an HTTP server with a given address and handler. The handler is usually nil, which means to use DefaultServeMux. Handle and HandleFunc add handlers to DefaultServeMux.
- More control over the server’s behavior is available by creating a custom Server.
- Package httputil provides HTTP utility functions, complementing the more common ones in the net/http package.