mirror of
https://github.com/caddyserver/caddy.git
synced 2025-04-22 04:18:47 +08:00
Coupla bug fixes
This commit is contained in:
parent
6825db3906
commit
08bf9e4fc0
17
context.go
17
context.go
@ -274,14 +274,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
|
||||
// we're done with the raw bytes; allow GC to deallocate
|
||||
val.Set(reflect.Zero(typ))
|
||||
|
||||
// if the loaded module happens to be an app that can emit events, store it so the
|
||||
// core can have access to emit events without an import cycle
|
||||
if ee, ok := result.(eventEmitter); ok {
|
||||
if _, ok := ee.(App); ok {
|
||||
ctx.cfg.eventEmitter = ee
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@ -445,6 +437,15 @@ func (ctx Context) LoadModuleByID(id string, rawMsg json.RawMessage) (any, error
|
||||
|
||||
ctx.moduleInstances[id] = append(ctx.moduleInstances[id], val)
|
||||
|
||||
// if the loaded module happens to be an app that can emit events, store it so the
|
||||
// core can have access to emit events without an import cycle
|
||||
if ee, ok := val.(eventEmitter); ok {
|
||||
if _, ok := ee.(App); ok {
|
||||
log.Println("GOT EE:", ee)
|
||||
ctx.cfg.eventEmitter = ee
|
||||
}
|
||||
}
|
||||
|
||||
return val, nil
|
||||
}
|
||||
|
||||
|
@ -212,9 +212,18 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) c
|
||||
logger.Error("failed to create event", zap.Error(err))
|
||||
}
|
||||
|
||||
var originModule caddy.ModuleInfo
|
||||
var originModuleID caddy.ModuleID
|
||||
var originModuleName string
|
||||
if origin := e.Origin(); origin != nil {
|
||||
originModule = origin.CaddyModule()
|
||||
originModuleID = originModule.ID
|
||||
originModuleName = originModule.String()
|
||||
}
|
||||
|
||||
logger = logger.With(
|
||||
zap.String("id", e.ID().String()),
|
||||
zap.String("origin", e.Origin().CaddyModule().String()))
|
||||
zap.String("origin", originModuleName))
|
||||
|
||||
// add event info to replacer, make sure it's in the context
|
||||
repl, ok := ctx.Context.Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
|
||||
@ -235,7 +244,7 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) c
|
||||
case "event.time_unix":
|
||||
return e.Timestamp().UnixMilli(), true
|
||||
case "event.module":
|
||||
return e.Origin().CaddyModule().ID, true
|
||||
return originModuleID, true
|
||||
case "event.data":
|
||||
return e.Data, true
|
||||
}
|
||||
@ -257,7 +266,7 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) c
|
||||
// invoke handlers bound to the event by name and also all events; this for loop
|
||||
// iterates twice at most: once for the event name, once for "" (all events)
|
||||
for {
|
||||
moduleID := e.Origin().CaddyModule().ID
|
||||
moduleID := originModuleID
|
||||
|
||||
// implement propagation up the module tree (i.e. start with "a.b.c" then "a.b" then "a" then "")
|
||||
for {
|
||||
|
Loading…
x
Reference in New Issue
Block a user