On Fri, Apr 3, 2020 at 7:10 PM joe mcguckin <j...@via.net> wrote:

> I see some code like:
>
>           r.NotFoundHandler =http.HandlerFunc(notfound)
>
> Where notfound() has the signature of
>
>           func notfound(w http.ResponseWriter, r *http.Request)
>
> What is HandlerFunc() doing? It’s not a function. Is it some sort of type
> coercion or casting?
>
I can see how casting that might work with simple values
> (e.g.numbers,integers, etc)  but functions?
>

It is a function that returns a function:
https://golang.org/pkg/net/http/#HandlerFunc.ServeHTTP. See also,
https://golang.org/src/net/http/server.go?s=61783:61843#L2001.

I'm guessing you've never used a language where functions are first-class
objects that can be used indirectly; as opposed to direct calls you can
search for using your editor/IDE. As the documentation states, it is an
adapter that converts one function type into another.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_cjFYnhoap0FtsbP5hLsc7RjcWGf1o5EFsb7Hzhu68%2BA%40mail.gmail.com.

Reply via email to