// NewHandler creates a new Handler. // // Routes cannot be modified after construction. The order that the route // names are returned by Routes.Paths() determines the lookup order. func NewHandler(c *Context) *Handler { return &Handler{ c: c, resolver: httputil.NewResolver([]string{}), routes: map[string]HandlerFunc{}, paths: []string{}, } }
// Add a route to a handler. // // The route name is "VERB /ENPOINT/PATH", e.g. "GET /foo". func (h *Handler) Add(route string, fn HandlerFunc) { log.Printf("Map %q to %s", route, reflect.ValueOf(fn).Type().Name()) h.routes[route] = fn h.paths = append(h.paths, route) h.resolver = httputil.NewResolver(h.paths) }