mirror of
https://github.com/coredns/coredns.git
synced 2026-10-08 19:45:21 -04:00
core/dnsserver: support explicit registration for embedded hosts (#8525)
* core/dnsserver: test host-plugin embedding with forward Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com> * core/dnsserver: add a directive setter for embedded hosts Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com> * core/dnsserver: support explicit server registration for embedded hosts Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com> --------- Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
33
core/dnsserver/directives.go
Normal file
33
core/dnsserver/directives.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package dnsserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// SetDirectives replaces [Directives] with a copy of directives, in execution
|
||||
// order. Names must be nonempty and unique. On error, Directives is unchanged.
|
||||
// An empty or nil list disables all directives.
|
||||
//
|
||||
// This selects directives but does not import or register plugins. A host may
|
||||
// register its plugins after this call, before starting Caddy. Unregistered
|
||||
// directives used in a Corefile are rejected by Caddy during startup.
|
||||
//
|
||||
// The list is process-wide, not per instance. Call SetDirectives before starting
|
||||
// any servers, not while servers are running. The caller must serialize it with
|
||||
// all other access to Directives, including startup and reload. It is not a
|
||||
// runtime reconfiguration API.
|
||||
func SetDirectives(directives []string) error {
|
||||
seen := make(map[string]struct{}, len(directives))
|
||||
for i, name := range directives {
|
||||
if name == "" {
|
||||
return fmt.Errorf("empty directive name at index %d", i)
|
||||
}
|
||||
if _, ok := seen[name]; ok {
|
||||
return fmt.Errorf("duplicate directive %q", name)
|
||||
}
|
||||
seen[name] = struct{}{}
|
||||
}
|
||||
Directives = slices.Clone(directives)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user