mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
chore: enable early-return and superfluous-else from revive (#7129)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -118,11 +118,10 @@ func autoParse(c *caddy.Controller) (Auto, error) {
|
||||
}
|
||||
_, err := os.Stat(a.directory)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log.Warningf("Directory does not exist: %s", a.directory)
|
||||
} else {
|
||||
if !os.IsNotExist(err) {
|
||||
return a, c.Errf("Unable to access root path '%s': %v", a.directory, err)
|
||||
}
|
||||
log.Warningf("Directory does not exist: %s", a.directory)
|
||||
}
|
||||
|
||||
// regexp template
|
||||
|
||||
@@ -149,12 +149,11 @@ func split255(s string) []string {
|
||||
sx := []string{}
|
||||
p, i := 0, 255
|
||||
for {
|
||||
if i <= len(s) {
|
||||
sx = append(sx, s[p:i])
|
||||
} else {
|
||||
if i > len(s) {
|
||||
sx = append(sx, s[p:])
|
||||
break
|
||||
}
|
||||
sx = append(sx, s[p:i])
|
||||
p, i = p+255, i+255
|
||||
}
|
||||
|
||||
|
||||
@@ -96,11 +96,10 @@ func hostsParse(c *caddy.Controller) (Hosts, error) {
|
||||
}
|
||||
s, err := os.Stat(h.path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log.Warningf("File does not exist: %s", h.path)
|
||||
} else {
|
||||
if !os.IsNotExist(err) {
|
||||
return h, c.Errf("unable to access hosts file '%s': %v", h.path, err)
|
||||
}
|
||||
log.Warningf("File does not exist: %s", h.path)
|
||||
}
|
||||
if s != nil && s.IsDir() {
|
||||
log.Warningf("Hosts file %q is a directory", h.path)
|
||||
|
||||
@@ -127,18 +127,17 @@ func (k *Kubernetes) External(state request.Request, headless bool) ([]msg.Servi
|
||||
}
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
for _, ip := range svc.ExternalIPs {
|
||||
for _, p := range svc.Ports {
|
||||
if !(matchPortAndProtocol(port, p.Name, protocol, string(p.Protocol))) {
|
||||
continue
|
||||
}
|
||||
rcode = dns.RcodeSuccess
|
||||
s := msg.Service{Host: ip, Port: int(p.Port), TTL: k.ttl}
|
||||
s.Key = strings.Join([]string{zonePath, svc.Namespace, svc.Name}, "/")
|
||||
|
||||
services = append(services, s)
|
||||
}
|
||||
for _, ip := range svc.ExternalIPs {
|
||||
for _, p := range svc.Ports {
|
||||
if !(matchPortAndProtocol(port, p.Name, protocol, string(p.Protocol))) {
|
||||
continue
|
||||
}
|
||||
rcode = dns.RcodeSuccess
|
||||
s := msg.Service{Host: ip, Port: int(p.Port), TTL: k.ttl}
|
||||
s.Key = strings.Join([]string{zonePath, svc.Namespace, svc.Name}, "/")
|
||||
|
||||
services = append(services, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,16 +194,15 @@ func (k *Kubernetes) ExternalServices(zone string, headless bool) (services []ms
|
||||
}
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
for _, ip := range svc.ExternalIPs {
|
||||
for _, p := range svc.Ports {
|
||||
s := msg.Service{Host: ip, Port: int(p.Port), TTL: k.ttl}
|
||||
s.Key = strings.Join([]string{zonePath, svc.Namespace, svc.Name}, "/")
|
||||
services = append(services, s)
|
||||
s.Key = strings.Join(append([]string{zonePath, svc.Namespace, svc.Name}, strings.ToLower("_"+string(p.Protocol)), strings.ToLower("_"+p.Name)), "/")
|
||||
s.TargetStrip = 2
|
||||
services = append(services, s)
|
||||
}
|
||||
}
|
||||
for _, ip := range svc.ExternalIPs {
|
||||
for _, p := range svc.Ports {
|
||||
s := msg.Service{Host: ip, Port: int(p.Port), TTL: k.ttl}
|
||||
s.Key = strings.Join([]string{zonePath, svc.Namespace, svc.Name}, "/")
|
||||
services = append(services, s)
|
||||
s.Key = strings.Join(append([]string{zonePath, svc.Namespace, svc.Name}, strings.ToLower("_"+string(p.Protocol)), strings.ToLower("_"+p.Name)), "/")
|
||||
s.TargetStrip = 2
|
||||
services = append(services, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,9 +212,8 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
|
||||
if ignore == "empty_service" {
|
||||
k8s.opts.ignoreEmptyService = true
|
||||
continue
|
||||
} else {
|
||||
return nil, fmt.Errorf("unable to parse ignore value: '%v'", ignore)
|
||||
}
|
||||
return nil, fmt.Errorf("unable to parse ignore value: '%v'", ignore)
|
||||
}
|
||||
case "kubeconfig":
|
||||
args := c.RemainingArgs()
|
||||
|
||||
@@ -23,15 +23,14 @@ func TransferIn(c *caddy.Controller) (froms []string, err error) {
|
||||
return nil, c.ArgErr()
|
||||
}
|
||||
for i := range froms {
|
||||
if froms[i] != "*" {
|
||||
normalized, err := HostPort(froms[i], transport.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
froms[i] = normalized
|
||||
} else {
|
||||
if froms[i] == "*" {
|
||||
return nil, fmt.Errorf("can't use '*' in transfer from")
|
||||
}
|
||||
normalized, err := HostPort(froms[i], transport.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
froms[i] = normalized
|
||||
}
|
||||
}
|
||||
return froms, nil
|
||||
|
||||
@@ -26,13 +26,12 @@ func setup(c *caddy.Controller) error {
|
||||
// Check if root path exists
|
||||
_, err := os.Stat(config.Root)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// Allow this, because the folder might appear later.
|
||||
// But make sure the user knows!
|
||||
log.Warningf("Root path does not exist: %s", config.Root)
|
||||
} else {
|
||||
if !os.IsNotExist(err) {
|
||||
return plugin.Error("root", c.Errf("unable to access root path '%s': %v", config.Root, err))
|
||||
}
|
||||
// Allow this, because the folder might appear later.
|
||||
// But make sure the user knows!
|
||||
log.Warningf("Root path does not exist: %s", config.Root)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user