* Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * More lint fixes This leaves: ~~~ middleware/kubernetes/nametemplate/nametemplate.go:64:6: exported type NameTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:71:1: exported method NameTemplate.SetTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:108:1: exported method NameTemplate.GetZoneFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:116:1: exported method NameTemplate.GetNamespaceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:120:1: exported method NameTemplate.GetServiceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:124:1: exported method NameTemplate.GetTypeFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:135:1: exported method NameTemplate.GetSymbolFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:167:1: exported method NameTemplate.IsValid should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:182:6: exported type NameValues should have comment or be unexported middleware/kubernetes/util/util.go:1:1: package comment should be of the form "Package util ..." middleware/kubernetes/util/util.go:27:2: exported const WildcardStar should have comment (or a comment on this block) or be unexported middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported ~~~ I plan on reworking the proxy anyway, so I'll leave that be.
111 lines
2 KiB
Go
111 lines
2 KiB
Go
package errors
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/miekg/coredns/core/dnsserver"
|
|
"github.com/miekg/coredns/middleware"
|
|
|
|
"github.com/hashicorp/go-syslog"
|
|
"github.com/mholt/caddy"
|
|
)
|
|
|
|
func init() {
|
|
caddy.RegisterPlugin("errors", caddy.Plugin{
|
|
ServerType: "dns",
|
|
Action: setup,
|
|
})
|
|
}
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
handler, err := errorsParse(c)
|
|
if err != nil {
|
|
return middleware.Error("errors", err)
|
|
}
|
|
|
|
var writer io.Writer
|
|
|
|
switch handler.LogFile {
|
|
case "visible":
|
|
handler.Debug = true
|
|
case "stdout":
|
|
writer = os.Stdout
|
|
case "stderr":
|
|
writer = os.Stderr
|
|
case "syslog":
|
|
writer, err = gsyslog.NewLogger(gsyslog.LOG_ERR, "LOCAL0", "coredns")
|
|
if err != nil {
|
|
return middleware.Error("errors", err)
|
|
}
|
|
default:
|
|
if handler.LogFile == "" {
|
|
writer = os.Stderr // default
|
|
break
|
|
}
|
|
|
|
var file *os.File
|
|
file, err = os.OpenFile(handler.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
|
if err != nil {
|
|
return middleware.Error("errors", err)
|
|
}
|
|
writer = file
|
|
}
|
|
handler.Log = log.New(writer, "", 0)
|
|
|
|
dnsserver.GetConfig(c).AddMiddleware(func(next middleware.Handler) middleware.Handler {
|
|
handler.Next = next
|
|
return handler
|
|
})
|
|
|
|
return nil
|
|
}
|
|
|
|
func errorsParse(c *caddy.Controller) (errorHandler, error) {
|
|
handler := errorHandler{}
|
|
|
|
optionalBlock := func() (bool, error) {
|
|
var hadBlock bool
|
|
|
|
for c.NextBlock() {
|
|
hadBlock = true
|
|
|
|
what := c.Val()
|
|
if !c.NextArg() {
|
|
return hadBlock, c.ArgErr()
|
|
}
|
|
where := c.Val()
|
|
|
|
if what == "log" {
|
|
if where == "visible" {
|
|
handler.Debug = true
|
|
} else {
|
|
handler.LogFile = where
|
|
}
|
|
}
|
|
}
|
|
return hadBlock, nil
|
|
}
|
|
|
|
for c.Next() {
|
|
// Configuration may be in a block
|
|
hadBlock, err := optionalBlock()
|
|
if err != nil {
|
|
return handler, err
|
|
}
|
|
|
|
// Otherwise, the only argument would be an error log file name or 'visible'
|
|
if !hadBlock {
|
|
if c.NextArg() {
|
|
if c.Val() == "visible" {
|
|
handler.Debug = true
|
|
} else {
|
|
handler.LogFile = c.Val()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return handler, nil
|
|
}
|