mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 02:33:21 -05:00 
			
		
		
		
	* plugins: Return error for multiple use of some Return plugin.ErrOnce when a plugin that doesn't support it, is called mutliple times. This now adds it for: cache, dnssec, errors, forward, hosts, nsid. And changes it slightly in kubernetes, pprof, reload, root. * more tests
		
			
				
	
	
		
			52 lines
		
	
	
		
			861 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			861 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package nsid
 | 
						|
 | 
						|
import (
 | 
						|
	"os"
 | 
						|
	"strings"
 | 
						|
 | 
						|
	"github.com/coredns/coredns/core/dnsserver"
 | 
						|
	"github.com/coredns/coredns/plugin"
 | 
						|
 | 
						|
	"github.com/mholt/caddy"
 | 
						|
)
 | 
						|
 | 
						|
func init() {
 | 
						|
	caddy.RegisterPlugin("nsid", caddy.Plugin{
 | 
						|
		ServerType: "dns",
 | 
						|
		Action:     setup,
 | 
						|
	})
 | 
						|
}
 | 
						|
 | 
						|
func setup(c *caddy.Controller) error {
 | 
						|
	nsid, err := nsidParse(c)
 | 
						|
	if err != nil {
 | 
						|
		return plugin.Error("nsid", err)
 | 
						|
	}
 | 
						|
 | 
						|
	dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
 | 
						|
		return Nsid{Next: next, Data: nsid}
 | 
						|
	})
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func nsidParse(c *caddy.Controller) (string, error) {
 | 
						|
	// Use hostname as the default
 | 
						|
	nsid, err := os.Hostname()
 | 
						|
	if err != nil {
 | 
						|
		nsid = "localhost"
 | 
						|
	}
 | 
						|
	i := 0
 | 
						|
	for c.Next() {
 | 
						|
		if i > 0 {
 | 
						|
			return nsid, plugin.ErrOnce
 | 
						|
		}
 | 
						|
		i++
 | 
						|
		args := c.RemainingArgs()
 | 
						|
		if len(args) > 0 {
 | 
						|
			nsid = strings.Join(args, " ")
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return nsid, nil
 | 
						|
}
 |