rule

package
v0.29.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2020 License: Apache-2.0 Imports: 10 Imported by: 7 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL