-2

I'm trying to understand the differences between Handle and HandleFunc.

Other than the differences, when would you use one over the other when building a Go web app?

https://golang.org/pkg/net/http/#Handle

cool breeze
  • 4,461
  • 5
  • 38
  • 67
  • 1
    "Other than the differences" -- the superficial difference is all there is. [The `ServeMux` calls `Handle` on both](https://github.com/golang/go/blob/23e8e197b0cd40312d96dd7576a44796f65dfb50/src/net/http/server.go#L2367) – JimB Feb 06 '18 at 18:40
  • There's *a lot* of online material -- blog posts, etc. -- about net/http and these functions. Not to mention stackoverflow questions that are nearly identical to the one you just asked, e.g. https://stackoverflow.com/questions/21957455/difference-between-http-handle-and-http-handlefunc – jrefior Feb 06 '18 at 18:40

1 Answers1

8

You'd use whichever one fits your handler implementation. If you've implemented your handler as a function, you'd use HandleFunc; if you've implemented it as a type with a ServeHTTP method, you'd use Handle.

Adrian
  • 42,911
  • 6
  • 107
  • 99