Skip to content

Instantly share code, notes, and snippets.

@AntonStoeckl
Created February 1, 2022 10:02
Show Gist options
  • Save AntonStoeckl/989d1a4d8c4461f09d669fa03bc88c74 to your computer and use it in GitHub Desktop.
Save AntonStoeckl/989d1a4d8c4461f09d669fa03bc88c74 to your computer and use it in GitHub Desktop.
Example for blog post: Go bits: Magic with functions
// The HandlerFunc type is an adapter to allow the use of
// ordinary functions as HTTP handlers. If f is a function
// with the appropriate signature, HandlerFunc(f) is a
// Handler that calls f.
type HandlerFunc func(ResponseWriter, *Request)
// ServeHTTP calls f(w, r).
func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request) {
f(w, r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment