events: Implement event system (#4912)

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
Francis Lavoie 2022-08-31 17:01:30 -04:00 committed by GitHub
parent 68d8ac9802
commit d4d8bbcfc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 569 additions and 34 deletions

View file

@ -36,6 +36,7 @@ import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyevents"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/caddyserver/caddy/v2/modules/caddyhttp/headers"
"github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite"
@ -193,6 +194,7 @@ type Handler struct {
ctx caddy.Context
logger *zap.Logger
events *caddyevents.App
}
// CaddyModule returns the Caddy module information.
@ -205,6 +207,11 @@ func (Handler) CaddyModule() caddy.ModuleInfo {
// Provision ensures that h is set up properly before use.
func (h *Handler) Provision(ctx caddy.Context) error {
eventAppIface, err := ctx.App("events")
if err != nil {
return fmt.Errorf("getting events app: %v", err)
}
h.events = eventAppIface.(*caddyevents.App)
h.ctx = ctx
h.logger = ctx.Logger(h)