Commit cbdd3a4f authored by Henrique Dias's avatar Henrique Dias Committed by Matt Holt

Add ExtraInfo to EventHook (#1692)

* Update plugins.go

* Add extraInfo to eventHook

* Add extraInfo to eventHook

* Update run.go

* Update run.go

* Update run.go
parent 6b8e40b3
...@@ -101,7 +101,7 @@ func Run() { ...@@ -101,7 +101,7 @@ func Run() {
} }
// Executes Startup events // Executes Startup events
caddy.EmitEvent(caddy.StartupEvent) caddy.EmitEvent(caddy.StartupEvent, nil)
// Get Caddyfile input // Get Caddyfile input
caddyfileinput, err := caddy.LoadCaddyfile(serverType) caddyfileinput, err := caddy.LoadCaddyfile(serverType)
......
...@@ -224,7 +224,7 @@ const ( ...@@ -224,7 +224,7 @@ const (
) )
// EventHook is a type which holds information about a startup hook plugin. // EventHook is a type which holds information about a startup hook plugin.
type EventHook func(eventType EventName) error type EventHook func(eventType EventName, eventInfo interface{}) error
// RegisterEventHook plugs in hook. All the hooks should register themselves // RegisterEventHook plugs in hook. All the hooks should register themselves
// and they must have a name. // and they must have a name.
...@@ -241,9 +241,9 @@ func RegisterEventHook(name string, hook EventHook) { ...@@ -241,9 +241,9 @@ func RegisterEventHook(name string, hook EventHook) {
// EmitEvent executes the different hooks passing the EventType as an // EmitEvent executes the different hooks passing the EventType as an
// argument. This is a blocking function. Hook developers should // argument. This is a blocking function. Hook developers should
// use 'go' keyword if they don't want to block Caddy. // use 'go' keyword if they don't want to block Caddy.
func EmitEvent(event EventName) { func EmitEvent(event EventName, info interface{}) {
for name, hook := range eventHooks { for name, hook := range eventHooks {
err := hook(event) err := hook(event, info)
if err != nil { if err != nil {
log.Printf("error on '%s' hook: %v", name, err) log.Printf("error on '%s' hook: %v", name, err)
......
...@@ -53,7 +53,7 @@ func trapSignalsCrossPlatform() { ...@@ -53,7 +53,7 @@ func trapSignalsCrossPlatform() {
func executeShutdownCallbacks(signame string) (exitCode int) { func executeShutdownCallbacks(signame string) (exitCode int) {
shutdownCallbacksOnce.Do(func() { shutdownCallbacksOnce.Do(func() {
// execute third-party shutdown hooks // execute third-party shutdown hooks
EmitEvent(ShutdownEvent) EmitEvent(ShutdownEvent, signame)
errs := allShutdownCallbacks() errs := allShutdownCallbacks()
if len(errs) > 0 { if len(errs) > 0 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment