1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 20:41:57 +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.

View File

@@ -20,6 +20,10 @@ type ConfigurationReadOnly interface {
GetSocketSharding() bool
// GetKeepAlive returns the KeepAlive field.
GetKeepAlive() time.Duration
// GetKeepAlive returns the Timeout field.
GetTimeout() time.Duration
// GetKeepAlive returns the TimeoutMessage field.
GetTimeoutMessage() string
// GetDisablePathCorrection returns the DisablePathCorrection field
GetDisablePathCorrection() bool
// GetDisablePathCorrectionRedirection returns the DisablePathCorrectionRedirection field.

View File

@@ -708,7 +708,6 @@ func (ctx *Context) StopExecution() {
// And stop.
ctx.currentHandlerIndex = stopExecutionIndex
}
}
// IsStopped reports whether the current position of the context's handlers is -1,
@@ -2697,7 +2696,6 @@ func (ctx *Context) ReadMsgPack(ptr interface{}) error {
// As a special case if the "ptr" was a pointer to string or []byte
// then it will bind it to the request body as it is.
func (ctx *Context) ReadBody(ptr interface{}) error {
// If the ptr is string or byte, read the body as it's.
switch v := ptr.(type) {
case *string:
@@ -4871,7 +4869,6 @@ func CookieAllowReclaim(cookieNames ...string) CookieOption {
header.Del("Cookie")
}
}
}
// CookieAllowSubdomains set to the Cookie Options
@@ -5888,5 +5885,12 @@ func (ctx *Context) GetID() interface{} {
// It returns the Context's ID given by a `SetID`call,
// followed by the client's IP and the method:uri.
func (ctx *Context) String() string {
return fmt.Sprintf("[%s] %s ▶ %s:%s", ctx.GetID(), ctx.RemoteAddr(), ctx.Method(), ctx.Request().RequestURI)
id := ctx.GetID()
if id != nil {
if stringer, ok := id.(fmt.Stringer); ok {
id = stringer.String()
}
}
return fmt.Sprintf("[%v] %s ▶ %s:%s", id, ctx.RemoteAddr(), ctx.Method(), ctx.Request().RequestURI)
}