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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user