diff --git a/README.md b/README.md index d5e449d5..dc8bea7d 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ With your help, we can improve Open Source web development for everyone! > Donations from [China](https://github.com/kataras/iris/issues/1870#issuecomment-1101418349) are now accepted!
+ @@ -276,7 +277,6 @@ With your help, we can improve Open Source web development for everyone! - @@ -297,6 +297,7 @@ With your help, we can improve Open Source web development for everyone! + @@ -305,6 +306,7 @@ With your help, we can improve Open Source web development for everyone! + @@ -336,6 +338,7 @@ With your help, we can improve Open Source web development for everyone! + @@ -391,6 +394,7 @@ With your help, we can improve Open Source web development for everyone! + @@ -398,6 +402,7 @@ With your help, we can improve Open Source web development for everyone! + @@ -405,7 +410,9 @@ With your help, we can improve Open Source web development for everyone! + + @@ -456,7 +463,11 @@ With your help, we can improve Open Source web development for everyone! ## 📖 Learning Iris -### Create a new project +### Installation + +The only requirement is the [Go Programming Language](https://go.dev/dl/). + +#### Create a new project ```sh $ mkdir myapp diff --git a/context/fs.go b/context/fs.go index 4b5dcc21..8ff8164a 100644 --- a/context/fs.go +++ b/context/fs.go @@ -132,7 +132,7 @@ var ResolveHTTPFS = func(fsOrDir interface{}) http.FileSystem { } // FindNames accepts a "http.FileSystem" and a root name and returns -// the list containg its file names. +// the list containing its file names. func FindNames(fileSystem http.FileSystem, name string) ([]string, error) { f, err := fileSystem.Open(name) if err != nil { diff --git a/context/handler.go b/context/handler.go index 60e03155..3a8cc631 100644 --- a/context/handler.go +++ b/context/handler.go @@ -21,6 +21,24 @@ var ( var ( handlerNames = make(map[*NameExpr]string) handlerNamesMu sync.RWMutex + + ignoreMainHandlerNames = [...]string{ + "iris.cache", + "iris.basicauth", + "iris.hCaptcha", + "iris.reCAPTCHA", + "iris.profiling", + "iris.recover", + "iris.accesslog", + "iris.grpc", + "iris.requestid", + "iris.rewrite", + "iris.cors", + "iris.jwt", + "iris.logger", + "iris.rate", + "iris.methodoverride", + } ) // SetHandlerName sets a handler name that could be @@ -48,6 +66,7 @@ func SetHandlerName(original string, replacement string) { literal: original, regex: regex, }] = replacement + handlerNamesMu.Unlock() } @@ -106,6 +125,7 @@ func valueOf(v interface{}) reflect.Value { func HandlerName(h interface{}) string { pc := valueOf(h).Pointer() name := runtime.FuncForPC(pc).Name() + handlerNamesMu.RLock() for expr, newName := range handlerNames { if expr.MatchString(name) { @@ -113,7 +133,6 @@ func HandlerName(h interface{}) string { break } } - handlerNamesMu.RUnlock() return trimHandlerName(name) @@ -217,6 +236,9 @@ var ignoreHandlerNames = [...]string{ "iris/core/router.ExecutionOptions.buildHandler", "iris/core/router.(*APIBuilder).Favicon", "iris/core/router.StripPrefix", + "iris/core/router.PrefixDir", + "iris/core/router.PrefixFS", + "iris/context.glob..func2.1", } // IgnoreHandlerName compares a static slice of Iris builtin @@ -232,19 +254,6 @@ func IgnoreHandlerName(name string) bool { return false } -var ignoreMainHandlerNames = [...]string{ - "iris.cache", - "iris.basicauth", - "iris.hCaptcha", - "iris.reCAPTCHA", - "iris.profiling", - "iris.recover", - "iris.accesslog", - "iris.grpc", - "iris.requestid", - "iris.rewrite", -} - // ingoreMainHandlerName reports whether a main handler of "name" should // be ignored and continue to match the next. // The ignored main handler names are literals and respects the `ignoreNameHandlers` too. diff --git a/core/router/api_builder.go b/core/router/api_builder.go index af4f5fae..3128deaf 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -1056,6 +1056,23 @@ func (api *APIBuilder) GetRoutes() []*Route { return api.routes.getAll() } +// CountHandlers returns the total number of all unique +// registered route handlers. +func (api *APIBuilder) CountHandlers() int { + uniqueNames := make(map[string]struct{}) + + for _, r := range api.GetRoutes() { + for _, h := range r.Handlers { + handlerName := context.HandlerName(h) + if _, exists := uniqueNames[handlerName]; !exists { + uniqueNames[handlerName] = struct{}{} + } + } + } + + return len(uniqueNames) +} + // GetRoute returns the registered route based on its name, otherwise nil. // One note: "routeName" should be case-sensitive. func (api *APIBuilder) GetRoute(routeName string) *Route {