Files
coredns/core/dnsserver/directives.go
houyuwushang 8a269232e4 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>
2026-09-10 20:54:41 -07:00

34 lines
1.1 KiB
Go

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
}