Пример #1
0
func (r Routes) Apply(router zerver.Router) error {
	for pat, rt := range r {
		if rt.Handler == nil {
			rt.Handler = rt.MapHandler
		}
		err := router.Handler(pat, rt.Handler)
		if err != nil {
			return err
		}
	}
	return nil
}
Пример #2
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
}
Пример #3
0
func Enable(monitorPath string, rt zerver.Router) (err error) {
	if monitorPath != "" {
		path = monitorPath
	}
	if !initRoutes() {
		return
	}

	for subpath, handler := range routes {
		if err = rt.Handler(path+subpath, handler); err != nil {
			return
		}
		options = append(options, "GET "+path+subpath+": "+infos[subpath]+"\n")
	}
	err = rt.Filter(path, zerver.FilterFunc(globalFilter))
	return
}
Пример #4
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
}