validator

package
v0.0.0-...-32f009b Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ObjTypeAddress = func(value otto.Value, objKey string) error {
	err := errors.New(fmt.Sprintf("Expected %s to be an ethereum address", objKey))
	if !value.IsString() {
		return err
	}
	if !eth.IsHexAddress(value.String()) {
		return err
	}
	return nil
}

validate an address

View Source
var ObjTypeBool = func(value otto.Value, objKey string) error {
	if !value.IsBoolean() {
		return fmt.Errorf("expected %s to be a bool", objKey)
	}
	return nil
}
View Source
var ObjTypeObject = func(value otto.Value, objKey string) error {
	if !value.IsObject() {
		return fmt.Errorf("expected %s to be a object", objKey)
	}
	return nil
}

validate if value is an object

View Source
var ObjTypeString = func(value otto.Value, objKey string) error {
	if !value.IsString() {
		return errors.New(fmt.Sprintf("Expected %s to be a string", objKey))
	}
	return nil
}

Validate if value is a string

View Source
var TypeFunction = func(call otto.FunctionCall, position int) error {
	if !call.Argument(position).IsFunction() {
		return errors.New(fmt.Sprintf("expected parameter %d to be of type function", position))
	}
	return nil
}
View Source
var TypeNumber = func(call otto.FunctionCall, position int) error {
	if !call.Argument(position).IsNumber() {
		return errors.New(fmt.Sprintf("expected parameter %d to be of type number", position))
	}
	return nil
}
View Source
var TypeObject = func(call otto.FunctionCall, position int) error {
	if !call.Argument(position).IsObject() {
		return errors.New(fmt.Sprintf("expected parameter %d to be of type object", position))
	}
	return nil
}
View Source
var TypeString = func(call otto.FunctionCall, position int) error {
	if !call.Argument(position).IsString() {
		return errors.New(fmt.Sprintf("expected parameter %d to be of type string", position))
	}
	return nil
}

Functions

This section is empty.

Types

type CallValidator

type CallValidator struct {
	// contains filtered or unexported fields
}

func New

func New() *CallValidator

func (*CallValidator) Set

func (v *CallValidator) Set(index int, validator *Validator)

add validation rule

func (*CallValidator) Validate

func (v *CallValidator) Validate(vm *otto.Otto, call otto.FunctionCall) *otto.Value

type ObjValidator

type ObjValidator struct {
	// contains filtered or unexported fields
}

func NewObjValidator

func NewObjValidator() *ObjValidator

func (*ObjValidator) Set

func (v *ObjValidator) Set(key string, validator ObjValueValidator, required bool)

add an validator item

func (*ObjValidator) Validate

func (v *ObjValidator) Validate(vm *otto.Otto, obj otto.Object) *otto.Value

type ObjValueValidator

type ObjValueValidator func(value otto.Value, objKey string) error

type Validator

type Validator = func(call otto.FunctionCall, position int) error

Jump to

Keyboard shortcuts

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