mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	* Move functions from pkg/transport to pkg/parse Although "parse" is a fairly generic name I believe this is somewhat better named. pkg/transport keeps a few constants that are uses throughout for the rest is is renaming a bunch (and the fallout from there to make things compile again). Signed-off-by: Miek Gieben <miek@miek.nl> * Fix tests Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Package parse contains functions that can be used in the setup code for plugins.
 | |
| package parse
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 
 | |
| 	"github.com/coredns/coredns/plugin/pkg/transport"
 | |
| 
 | |
| 	"github.com/mholt/caddy"
 | |
| )
 | |
| 
 | |
| // Transfer parses transfer statements: 'transfer [to|from] [address...]'.
 | |
| func Transfer(c *caddy.Controller, secondary bool) (tos, froms []string, err error) {
 | |
| 	if !c.NextArg() {
 | |
| 		return nil, nil, c.ArgErr()
 | |
| 	}
 | |
| 	value := c.Val()
 | |
| 	switch value {
 | |
| 	case "to":
 | |
| 		tos = c.RemainingArgs()
 | |
| 		for i := range tos {
 | |
| 			if tos[i] != "*" {
 | |
| 				normalized, err := HostPort(tos[i], transport.Port)
 | |
| 				if err != nil {
 | |
| 					return nil, nil, err
 | |
| 				}
 | |
| 				tos[i] = normalized
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 	case "from":
 | |
| 		if !secondary {
 | |
| 			return nil, nil, fmt.Errorf("can't use `transfer from` when not being a secondary")
 | |
| 		}
 | |
| 		froms = c.RemainingArgs()
 | |
| 		for i := range froms {
 | |
| 			if froms[i] != "*" {
 | |
| 				normalized, err := HostPort(froms[i], transport.Port)
 | |
| 				if err != nil {
 | |
| 					return nil, nil, err
 | |
| 				}
 | |
| 				froms[i] = normalized
 | |
| 			} else {
 | |
| 				return nil, nil, fmt.Errorf("can't use '*' in transfer from")
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	return
 | |
| }
 |