From 8ea223296348f117eb1b8b6528b1af588320266c Mon Sep 17 00:00:00 2001 From: Jordan Whited Date: Tue, 12 May 2020 17:40:19 -0700 Subject: [PATCH] construct wgctrl client in setup() --- setup.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/setup.go b/setup.go index c6b4318..76f82bc 100644 --- a/setup.go +++ b/setup.go @@ -1,9 +1,12 @@ package wgsd import ( + "fmt" + "github.com/caddyserver/caddy" "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" + "golang.zx2c4.com/wireguard/wgctrl" ) func init() { @@ -11,9 +14,20 @@ func init() { } func setup(c *caddy.Controller) error { + client, err := wgctrl.New() + if err != nil { + return fmt.Errorf("wgsd: error constructing wgctrl client: %v", + err) + } + + // TODO: parse zone and wireguard device name from config + // Add the Plugin to CoreDNS, so Servers can use it in their plugin chain. dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler { - return &WGSD{Next: next} + return &WGSD{ + Next: next, + client: client, + } }) return nil