Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Placeholder = validation.Match(PlaceholderRegex).Error("must be a variable placeholder like $marmotVariable")

	Address = validation.NewStringRule(IsAddress,
		fmt.Sprintf("must be valid 20 byte hex-encoded string like '%v'", exampleAddress))

	AddressOrPlaceholder = Or(Placeholder, Address)

	Relation = validation.In("eq", "ne", "ge", "gt", "le", "lt", "==", "!=", ">=", ">", "<=", "<")

	PermissionOrPlaceholder = Or(Placeholder, Permission)

	Permission = validation.By(func(value interface{}) error {
		str, err := validation.EnsureString(value)
		if err != nil {
			return fmt.Errorf("must be a permission name, but %v is not a string", value)
		}
		_, err = permission.PermStringToFlag(str)
		if err != nil {
			return err
		}
		return nil
	})

	Uint64OrPlaceholder = Or(Placeholder, Uint64)

	Uint64 = validation.By(func(value interface{}) error {
		str, err := validation.EnsureString(value)
		if err != nil {
			return fmt.Errorf("should be a numeric string but '%v' is not a string", value)
		}
		_, err = strconv.ParseUint(str, 10, 64)
		if err != nil {
			return fmt.Errorf("should be a 64 bit unsigned integer: ")
		}
		return nil
	})
)

    Rules

    View Source
    var PlaceholderRegex = regexp.MustCompile(`\$(?P<bracket>{?)(?P<job>[[:word:]]+)(\.(?P<variable>[[:word:]]+))?}?`)

    Functions

    func Exactly

    func Exactly(identity interface{}) validation.Rule

    func IsAddress

    func IsAddress(value string) bool

    func IsOmitted

    func IsOmitted(value interface{}) bool

      Returns true IFF value is zero value or has length 0

      func New

      func New(isValid func(value interface{}) bool, message string, args ...interface{}) *boolRule

      func Or

      func Or(rules ...validation.Rule) *orRule

      Types

      type PlaceholderMatch

      type PlaceholderMatch struct {
      	Match        string
      	JobName      string
      	VariableName string
      }

      func MatchPlaceholders

      func MatchPlaceholders(str string) []PlaceholderMatch

      func NewPlaceholderMatch

      func NewPlaceholderMatch(match []string) (pm PlaceholderMatch)

      func (PlaceholderMatch) IsMatch

      func (pm PlaceholderMatch) IsMatch() bool

      func (PlaceholderMatch) String

      func (pm PlaceholderMatch) String() string

      Source Files