Browse Source

Remove web.HandlerFunc

Since Goji accepts the underlying version of this type (i.e., the raw
function), and since it doesn't use web.Handler in the same way as the
net/http ecosystem uses http.Handler, there's really no reason to ever
use web.HandlerFunc.

This is a breaking change. Developers who previously used the
web.HandlerFunc type are encouraged to inline it into their own
projects.
Carl Jackson 11 years ago
parent
commit
aee21eb0bd
2 changed files with 2 additions and 22 deletions
  1. +2
    -6
      web/router_test.go
  2. +0
    -16
      web/web.go

+ 2
- 6
web/router_test.go View File

@ -88,8 +88,7 @@ var testHandlerTable = map[string]string{
"/a": "http fn",
"/b": "http handler",
"/c": "web fn",
"/d": "web handler",
"/e": "httpc",
"/d": "httpc",
}
func TestHandlerTypes(t *testing.T) {
@ -106,10 +105,7 @@ func TestHandlerTypes(t *testing.T) {
m.Get("/c", func(c C, w http.ResponseWriter, r *http.Request) {
ch <- "web fn"
})
m.Get("/d", HandlerFunc(func(c C, w http.ResponseWriter, r *http.Request) {
ch <- "web handler"
}))
m.Get("/e", testHandler(ch))
m.Get("/d", testHandler(ch))
for route, response := range testHandlerTable {
r, _ := http.NewRequest("GET", route, nil)


+ 0
- 16
web/web.go View File

@ -38,22 +38,6 @@ type Handler interface {
ServeHTTPC(C, http.ResponseWriter, *http.Request)
}
// HandlerFunc is similar to net/http's http.HandlerFunc, but supports a context
// object. Implements both http.Handler and Handler.
type HandlerFunc func(C, http.ResponseWriter, *http.Request)
// ServeHTTP implements http.Handler, allowing HandlerFunc's to be used with
// net/http and other compliant routers. When used in this way, the underlying
// function will be passed an empty context.
func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h(C{}, w, r)
}
// ServeHTTPC implements Handler.
func (h HandlerFunc) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {
h(c, w, r)
}
/*
PatternType is the type denoting Patterns and types that Goji internally
converts to Pattern (via the ParsePattern function). In order to provide an


Loading…
Cancel
Save