mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-10-28 01:32:01 +08:00
61 lines
1022 B
Go
61 lines
1022 B
Go
package dns
|
|
|
|
import (
|
|
"bytes"
|
|
"text/template"
|
|
)
|
|
|
|
type CoreFile struct {
|
|
Content []byte
|
|
}
|
|
|
|
// Body Gets the Caddyfile contents
|
|
func (c *CoreFile) Body() []byte {
|
|
return c.Content
|
|
}
|
|
|
|
// Path Gets the path to the origin file
|
|
func (c *CoreFile) Path() string {
|
|
return "CoreFile"
|
|
}
|
|
|
|
// ServerType The type of server this input is intended for
|
|
func (c *CoreFile) ServerType() string {
|
|
return "dns"
|
|
}
|
|
|
|
type CoreFileTmpl struct {
|
|
UpstreamDNS string
|
|
Nameservers string
|
|
}
|
|
|
|
func BuildCoreFile(corefileTmpl CoreFileTmpl) (*CoreFile, error) {
|
|
tplText := `
|
|
.:53 {
|
|
bind 127.0.0.1
|
|
forward cluster.local {{ .UpstreamDNS }}
|
|
forward . {{ .Nameservers }} {{ .UpstreamDNS }} {
|
|
policy sequential
|
|
max_concurrent 1
|
|
}
|
|
cache 30
|
|
log
|
|
errors
|
|
reload
|
|
}`
|
|
|
|
tpl, err := template.New("corefile").Parse(tplText)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
data := bytes.NewBuffer(nil)
|
|
if err := tpl.Execute(data, corefileTmpl); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &CoreFile{
|
|
Content: data.Bytes(),
|
|
}, nil
|
|
}
|