Created
February 1, 2022 10:02
-
-
Save AntonStoeckl/989d1a4d8c4461f09d669fa03bc88c74 to your computer and use it in GitHub Desktop.
Example for blog post: Go bits: Magic with functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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