mirror of
https://github.com/coredns/coredns.git
synced 2026-10-09 03:55: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:
@@ -12,6 +12,27 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func ExampleSetDirectives() {
|
||||
oldDirectives := dnsserver.Directives
|
||||
defer func() { dnsserver.Directives = oldDirectives }()
|
||||
|
||||
if err := dnsserver.SetDirectives([]string{"bind", "whoami"}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(dnsserver.Directives)
|
||||
// Output: [bind whoami]
|
||||
}
|
||||
|
||||
func ExampleRegister() {
|
||||
// Required before caddy.Start in builds with coredns_manual_registration;
|
||||
// harmless when the default import-time registration has already run.
|
||||
if err := dnsserver.Register(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("registered")
|
||||
// Output: registered
|
||||
}
|
||||
|
||||
func Example_embedding() {
|
||||
oldDirectives := dnsserver.Directives
|
||||
oldCaddyQuiet := caddy.Quiet
|
||||
@@ -25,6 +46,9 @@ func Example_embedding() {
|
||||
// Import only the plugins the host needs and set their execution order
|
||||
// before starting the first server.
|
||||
dnsserver.Directives = []string{"bind", "whoami"}
|
||||
if err := dnsserver.Register(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
caddy.Quiet = true
|
||||
dnsserver.Quiet = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user