Exemple #1
0
func (r Routes) convertFilters(filters []interface{}) []zerver.Filter {
	res := make([]zerver.Filter, len(filters))
	for i, f := range filters {
		if ft, is := f.(zerver.Filter); is {
			res[i] = ft
		} else if fn, is := f.(zerver.FilterFunc); is {
			res[i] = fn
		} else if fn, is := f.(func(zerver.Request, zerver.Response, zerver.FilterChain)); is {
			res[i] = zerver.FilterFunc(fn)
		} else {
			panic(fmt.Errorf("interceptor at index %d is not a filter.", i))
		}
	}
	return res
}
Exemple #2
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
}