示例#1
0
func (r Routes) Apply(rt zerver.Router) error {
	var err error
	for i := 0; err == nil && i < len(r); i++ {
		var route = r[i]
		if route.Handler != nil {
			err = rt.Handle(route.Pattern, route.Handler)
		} else {
			err = rt.HandleFunc(route.Pattern,
				route.Method,
				zerver.Intercept(route.HandleFunc,
					route.Interceptors...))
		}
	}

	return err
}
示例#2
0
func Enable(p string, rt zerver.Router, rootFilters zerver.RootFilters) (err error) {
	if p != "" {
		path = p
	}
	if !initRoutes() {
		return
	}

	for subpath, handler := range routes {
		if err = rt.HandleFunc(path+subpath, "GET", handler); err != nil {
			return
		}
		options = append(options, "GET "+path+subpath+": "+infos[subpath]+"\n")
	}

	if rootFilters == nil {
		err = rt.Handle(path, globalFilter)
	} else {
		rootFilters.Add(globalFilter)
	}

	return
}