coredns/plugin/pkg/parse/parse.go
Matthieu MOREL 186e4a1dbb
chore: enable early-return and superfluous-else from revive (#7129)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-06-05 10:10:58 +03:00

38 lines
843 B
Go

// Package parse contains functions that can be used in the setup code for plugins.
package parse
import (
"fmt"
"github.com/coredns/caddy"
"github.com/coredns/coredns/plugin/pkg/transport"
)
// TransferIn parses transfer statements: 'transfer from [address...]'.
func TransferIn(c *caddy.Controller) (froms []string, err error) {
if !c.NextArg() {
return nil, c.ArgErr()
}
value := c.Val()
switch value {
default:
return nil, c.Errf("unknown property %s", value)
case "from":
froms = c.RemainingArgs()
if len(froms) == 0 {
return nil, c.ArgErr()
}
for i := range froms {
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
}