Browse Source

Link to godoc in type-check error messages

This beats trying to enumerate the accepted types by hand.
Carl Jackson 11 years ago
parent
commit
7558aee4ad
3 changed files with 11 additions and 11 deletions
  1. +3
    -3
      web/middleware.go
  2. +4
    -3
      web/pattern.go
  3. +4
    -5
      web/router.go

+ 3
- 3
web/middleware.go View File

@ -50,6 +50,8 @@ func (s *cStack) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {
s.m.ServeHTTP(w, r)
}
const unknownMiddleware = `Unknown middleware type %T. See http://godoc.org/github.com/zenazn/goji/web#MiddlewareType for a list of acceptable types.`
func (m *mStack) appendLayer(fn interface{}) {
ml := mLayer{orig: fn}
switch f := fn.(type) {
@ -60,9 +62,7 @@ func (m *mStack) appendLayer(fn interface{}) {
case func(*C, http.Handler) http.Handler:
ml.fn = f
default:
log.Fatalf(`Unknown middleware type %v. Expected a function `+
`with signature "func(http.Handler) http.Handler" or `+
`"func(*web.C, http.Handler) http.Handler".`, fn)
log.Fatalf(unknownMiddleware, fn)
}
m.stack = append(m.stack, ml)
}


+ 4
- 3
web/pattern.go View File

@ -31,6 +31,8 @@ type Pattern interface {
Run(r *http.Request, c *C)
}
const unknownPattern = `Unknown pattern type %T. See http://godoc.org/github.com/zenazn/goji/web#PatternType for a list of acceptable types.`
/*
ParsePattern is used internally by Goji to parse route patterns. It is exposed
publicly to make it easier to write thin wrappers around the built-in Pattern
@ -50,8 +52,7 @@ func ParsePattern(raw PatternType) Pattern {
case string:
return parseStringPattern(v)
default:
log.Fatalf("Unknown pattern type %T. Expected a web.Pattern, "+
"regexp.Regexp, or a string.", v)
log.Fatalf(unknownPattern, v)
panic("log.Fatalf does not return")
}
panic("log.Fatalf does not return")
}

+ 4
- 5
web/router.go View File

@ -66,6 +66,8 @@ func (h netHTTPWrap) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {
h.Handler.ServeHTTP(w, r)
}
const unknownHandler = `Unknown handler type %T. See http://godoc.org/github.com/zenazn/goji/web#HandlerType for a list of acceptable types.`
func parseHandler(h interface{}) Handler {
switch f := h.(type) {
case Handler:
@ -77,12 +79,9 @@ func parseHandler(h interface{}) Handler {
case func(w http.ResponseWriter, r *http.Request):
return netHTTPWrap{http.HandlerFunc(f)}
default:
log.Fatalf("Unknown handler type %v. Expected a web.Handler, "+
"a http.Handler, or a function with signature func(C, "+
"http.ResponseWriter, *http.Request) or "+
"func(http.ResponseWriter, *http.Request)", h)
log.Fatalf(unknownHandler, h)
panic("log.Fatalf does not return")
}
panic("log.Fatalf does not return")
}
func httpMethod(mname string) method {


Loading…
Cancel
Save