mirror of
https://github.com/caddyserver/caddy.git
synced 2026-06-07 06:25:24 -04:00
Merge branch 'master' into diagnostics
# Conflicts: # plugins.go # vendor/manifest
This commit is contained in:
+27
-14
@@ -19,6 +19,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"github.com/mholt/caddy/caddyfile"
|
||||
)
|
||||
@@ -38,7 +39,7 @@ var (
|
||||
|
||||
// eventHooks is a map of hook name to Hook. All hooks plugins
|
||||
// must have a name.
|
||||
eventHooks = make(map[string]EventHook)
|
||||
eventHooks = sync.Map{}
|
||||
|
||||
// parsingCallbacks maps server type to map of directive
|
||||
// to list of callback functions. These aren't really
|
||||
@@ -98,11 +99,15 @@ func ListPlugins() map[string][]string {
|
||||
p["caddyfile_loaders"] = append(p["caddyfile_loaders"], defaultCaddyfileLoader.name)
|
||||
}
|
||||
|
||||
// event hook plugins
|
||||
if len(eventHooks) > 0 {
|
||||
for name := range eventHooks {
|
||||
p["event_hooks"] = append(p["event_hooks"], name)
|
||||
}
|
||||
// List the event hook plugins
|
||||
hooks := ""
|
||||
eventHooks.Range(func(k, _ interface{}) bool {
|
||||
hooks += " hook." + k.(string) + "\n"
|
||||
return true
|
||||
})
|
||||
if hooks != "" {
|
||||
str += "\nEvent hook plugins:\n"
|
||||
str += hooks
|
||||
}
|
||||
|
||||
// alphabetize the rest of the plugins
|
||||
@@ -220,7 +225,7 @@ type ServerType struct {
|
||||
// startup phases before this one. It's a way to keep
|
||||
// each set of server instances separate and to reduce
|
||||
// the amount of global state you need.
|
||||
NewContext func() Context
|
||||
NewContext func(inst *Instance) Context
|
||||
}
|
||||
|
||||
// Plugin is a type which holds information about a plugin.
|
||||
@@ -277,23 +282,23 @@ func RegisterEventHook(name string, hook EventHook) {
|
||||
if name == "" {
|
||||
panic("event hook must have a name")
|
||||
}
|
||||
if _, dup := eventHooks[name]; dup {
|
||||
_, dup := eventHooks.LoadOrStore(name, hook)
|
||||
if dup {
|
||||
panic("hook named " + name + " already registered")
|
||||
}
|
||||
eventHooks[name] = hook
|
||||
}
|
||||
|
||||
// EmitEvent executes the different hooks passing the EventType as an
|
||||
// argument. This is a blocking function. Hook developers should
|
||||
// use 'go' keyword if they don't want to block Caddy.
|
||||
func EmitEvent(event EventName, info interface{}) {
|
||||
for name, hook := range eventHooks {
|
||||
err := hook(event, info)
|
||||
|
||||
eventHooks.Range(func(k, v interface{}) bool {
|
||||
err := v.(EventHook)(event, info)
|
||||
if err != nil {
|
||||
log.Printf("error on '%s' hook: %v", name, err)
|
||||
log.Printf("error on '%s' hook: %v", k.(string), err)
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// ParsingCallback is a function that is called after
|
||||
@@ -412,6 +417,14 @@ func loadCaddyfileInput(serverType string) (Input, error) {
|
||||
return caddyfileToUse, nil
|
||||
}
|
||||
|
||||
// OnProcessExit is a list of functions to run when the process
|
||||
// exits -- they are ONLY for cleanup and should not block,
|
||||
// return errors, or do anything fancy. They will be run with
|
||||
// every signal, even if "shutdown callbacks" are not executed.
|
||||
// This variable must only be modified in the main goroutine
|
||||
// from init() functions.
|
||||
var OnProcessExit []func()
|
||||
|
||||
// caddyfileLoader pairs the name of a loader to the loader.
|
||||
type caddyfileLoader struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user