Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( Unterminated errorCause = iota MissingVariableName InvalidVariableName UndefinedVariable UnmatchedRightParen )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface {
ServeHTTP(http.ResponseWriter, *http.Request, interface{})
}
Analogous to http.Handler, ServeHTTP will be called with an empty interface which can be cast to the type the Handler was registered with.
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request, interface{})
func (HandlerFunc) ServeHTTP ¶
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, params interface{})
type PatternCompileError ¶
type PatternCompileError struct {
// contains filtered or unexported fields
}
func (*PatternCompileError) Error ¶
func (err *PatternCompileError) Error() string
type RegexpRouter ¶
type RegexpRouter struct {
// contains filtered or unexported fields
}
A http.Handler that will take the usual http request and response and re-route it to the appropriate rhttp.Handler.
Example ¶
w := new(ResponseWriterMock) type P struct { S string `rhttp:"s"` } f := func(w http.ResponseWriter, r *http.Request, i interface{}) { params := i.(*P) fmt.Printf("%s\n", params.S) } router := NewRouter() router.HandleFunc("/(s=[abc])", f, &P{}) r, _ := http.NewRequest("GET", "/a", strings.NewReader("")) router.ServeHTTP(w, r) r, _ = http.NewRequest("GET", "/b", strings.NewReader("")) router.ServeHTTP(w, r) w.WriteHeader(0) r, _ = http.NewRequest("GET", "/d", strings.NewReader("")) router.ServeHTTP(w, r) fmt.Printf("%d\n", w.GetCode())
Output: a b 404
func (*RegexpRouter) Handle ¶
func (r *RegexpRouter) Handle(pattern string, handler Handler, params interface{})
Registers a Handler with the RegexpRouter.
func (*RegexpRouter) HandleFunc ¶
func (r *RegexpRouter) HandleFunc(pattern string, f func(http.ResponseWriter, *http.Request, interface{}), params interface{})
An adapter allowing an appropriate function to also be registered.
func (*RegexpRouter) ServeHTTP ¶
func (r *RegexpRouter) ServeHTTP(w http.ResponseWriter, req *http.Request)
Reroute the request to the appropriate rhttp.Handler using req.Path
Click to show internal directories.
Click to hide internal directories.