liveBook · Manning

Http.HandlerFunc

http.HandlerFunc is a Go function type that adapts a request-handling function to the http.Handler interface.

How 2 Manning books explain it

Learn Go with Pocket-Sized Projects

http.HandlerFunc is Go's net/http function adapter type for handling an HTTP request and writing its response.

How it is used
Connects Go HTTP routes and test servers to functions that handle requests and write responses.
How deep it goes
Works through registration, path-value lookup, early error returns, and direct handler tests; does not examine adapter internals.
Examples
Uses a game-status endpoint, a habit-tick endpoint, and a test server returning an HTTP response.
What you can do after
Build it from scratch as a routed endpoint, then test it directly or use it to supply a test-server response.

Read how Learn Go with Pocket-Sized Projects explains http.HandlerFunc →

Go by Example

http.HandlerFunc is a Go function type that adapts a function with an HTTP handler signature to the http.Handler interface.

How it is used
Adapts ordinary HTTP functions and closures for servers, routing, and test servers that require http.Handler.
How deep it goes
Defines the adapter and its delegating ServeHTTP method, then applies it to production and testing examples.
Examples
Uses Health serving, a dependency-injected Shorten closure, and an httptest.Server closure.
What you can do after
Build HTTP services and tests by converting functions or closures with http.HandlerFunc for ListenAndServe and httptest.NewServer.

Read how Go by Example explains http.HandlerFunc →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.