github.com/avenga/couper@v1.12.2/config/runtime/server_validation.go (about)

     1  package runtime
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  )
     7  
     8  // reValidFormat validates the format only, validating for a valid host or port is out of scope.
     9  var reValidFormat = regexp.MustCompile(`^([a-z0-9.-]+|\*)(:\*|:\d{1,5})?$`)
    10  
    11  func validateHosts(serverName string, hosts []string, isHostsMandatory bool) error {
    12  	if isHostsMandatory && len(hosts) == 0 {
    13  		return fmt.Errorf("the hosts attribute is mandatory for multiple servers: %q", serverName)
    14  	}
    15  
    16  	for _, host := range hosts {
    17  		if !reValidFormat.MatchString(host) {
    18  			return fmt.Errorf("the host format is invalid: %q", host)
    19  		}
    20  	}
    21  
    22  	return nil
    23  }