parse config
This commit is contained in:
parent
81ce0257c4
commit
03b3375f8c
26
setup.go
26
setup.go
@ -6,8 +6,11 @@ import (
|
|||||||
"github.com/coredns/caddy"
|
"github.com/coredns/caddy"
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = clog.NewWithPlugin("overide")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
plugin.Register("override", setup)
|
plugin.Register("override", setup)
|
||||||
}
|
}
|
||||||
@ -31,10 +34,25 @@ func setup(c *caddy.Controller) error {
|
|||||||
func parseRules(c *caddy.Controller) ([]Rule, error) {
|
func parseRules(c *caddy.Controller) ([]Rule, error) {
|
||||||
var rules []Rule
|
var rules []Rule
|
||||||
|
|
||||||
rules = append(rules, Rule{
|
for c.Next() {
|
||||||
Search: net.ParseIP("45.9.63.244"),
|
for c.NextBlock() {
|
||||||
Override: net.ParseIP("10.0.0.1"),
|
searchIP := net.ParseIP(c.Val())
|
||||||
})
|
if searchIP == nil {
|
||||||
|
return nil, c.Errf("invalid search IP: %s", c.Val())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !c.NextArg() {
|
||||||
|
return nil, c.ArgErr()
|
||||||
|
}
|
||||||
|
|
||||||
|
overrideIP := net.ParseIP(c.Val())
|
||||||
|
if overrideIP == nil {
|
||||||
|
return nil, c.Errf("invalid override IP: %s", c.Val())
|
||||||
|
}
|
||||||
|
|
||||||
|
rules = append(rules, Rule{Search: searchIP, Override: overrideIP})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rules, nil
|
return rules, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user