github.com/koko1123/flow-go-1@v0.29.6/network/validator/any_validator.go (about)

     1  package validator
     2  
     3  import (
     4  	"github.com/koko1123/flow-go-1/network"
     5  )
     6  
     7  var _ network.MessageValidator = (*AnyValidator)(nil)
     8  
     9  // AnyValidator returns true if any of the given validators returns true
    10  type AnyValidator struct {
    11  	validators []network.MessageValidator
    12  }
    13  
    14  func NewAnyValidator(validators ...network.MessageValidator) network.MessageValidator {
    15  	return &AnyValidator{
    16  		validators: validators,
    17  	}
    18  }
    19  
    20  func (v AnyValidator) Validate(msg network.IncomingMessageScope) bool {
    21  	for _, validator := range v.validators {
    22  		if validator.Validate(msg) {
    23  			return true
    24  		}
    25  	}
    26  	return false
    27  }