1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 04:47:02 +00:00

new Timeout, TimeoutMessage configuration fields and apps.OnApplicationRegistered listener

This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-12-09 14:44:03 +02:00
parent 968a9ec06c
commit d6cfe3fe5b
9 changed files with 124 additions and 7 deletions

View File

@@ -113,8 +113,9 @@ var (
// It's slice instead of map because if IRIS_APP_NAME env var exists,
// by-default all applications running on the same machine
// will have the same name unless `Application.SetName` is called.
registeredApps []Application
mu sync.RWMutex
registeredApps []Application
onApplicationRegisteredListeners []func(Application)
mu sync.RWMutex
)
// RegisterApplication registers an application to the global shared storage.
@@ -126,6 +127,20 @@ func RegisterApplication(app Application) {
mu.Lock()
registeredApps = append(registeredApps, app)
mu.Unlock()
mu.RLock()
for _, listener := range onApplicationRegisteredListeners {
listener(app)
}
mu.RUnlock()
}
// OnApplicationRegistered adds a function which fires when a new application
// is registered.
func OnApplicationRegistered(listeners ...func(app Application)) {
mu.Lock()
onApplicationRegisteredListeners = append(onApplicationRegisteredListeners, listeners...)
mu.Unlock()
}
// GetApplications returns a slice of all the registered Applications.