expect

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CaseInvalid     = iota
	CaseGt          //  >
	CaseGe          //  >=
	CaseLt          //  <
	CaseLe          //  <=
	CaseEq          //  ==
	CaseNe          //  !=
	CaseContains    // for string.
	CaseNotContains // for string.
)
View Source
const ConfigBoolKeyName = "key_bool"
View Source
const ConfigDoubleKeyName = "key_double"
View Source
const ConfigExistKeyName = "key_exists"
View Source
const ConfigIntKeyName = "key_int"
View Source
const ConfigNotExistKeyName = "key_not_exists"
View Source
const ConfigStrKeyName = "key_str"
View Source
const ConfigUintKeyName = "key_uint"
View Source
const ParamNumMax = 16

Variables

View Source
var ErrInvalidCondition = errors.New("Invalid condition")

Functions

func IntCase2Str

func IntCase2Str(i int) string

IntCase2Str converts int case to string case.

e.g. CaseGe -> ">="

func Str2IntCase

func Str2IntCase(s string) int

Str2IntCase converts string case to int case.

e.g. ">=" ->  CaseGe

Types

type Condition

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

func NewBoolCondition

func NewBoolCondition(c int, b bool) (*Condition, error)

NewBoolCondition returns Condition c of boolean.

c must be CaseEq or CaseNe.

func NewDoubleCondition

func NewDoubleCondition(c int, d float64) (*Condition, error)

NewDoubleCondition returns Condition c of double

c must be CaseEq, CaseNe CaseGt, CaseGe, CaseLt or CaseLe.

func NewIntCondition

func NewIntCondition(c int, i int) (*Condition, error)

NewIntCondition returns Condition c of int.

c must be CaseEq, CaseNe CaseGt, CaseGe, CaseLt or CaseLe.

func NewStringCondition

func NewStringCondition(c int, s string) (*Condition, error)

NewStringCondition returns Condition c of string.

c must be CaseEq, CaseNe CaseContains or CaseNotContains.

func NewUintCondition

func NewUintCondition(c int, i uint) (*Condition, error)

NewUintCondition returns Condition c of uint.

c must be CaseEq, CaseNe CaseGt, CaseGe, CaseLt or CaseLe.

func (Condition) Compare

func (c Condition) Compare(ic Condition) bool

Compare compares c and ic.

func (Condition) IsMatch

func (c Condition) IsMatch(v interface{}) (bool, error)

IsMatch check if v matches condition.

func (Condition) String

func (c Condition) String() string

type Config

type Config struct {
	Exists         []Keys
	NotExists      []Keys
	TypeConditions []TypeCondition
}

Config represents context of this plugin.

func (*Config) HasExistKeys

func (cnf *Config) HasExistKeys(ks *Keys) bool

HasExistKeys check if ExistKeys of cnf has ks keys or not.

func (*Config) HasNotExistKeys

func (cnf *Config) HasNotExistKeys(ks *Keys) bool

HasNotExistKeys check if NotExistKeys of cnf has ks keys or not.

func (*Config) HasTypeCondition

func (cnf *Config) HasTypeCondition(t *TypeCondition) bool

HasTypeCondition check if TypeConditions of cnf has t or not.

func (*Config) SetExist

func (cnf *Config) SetExist(c *ConfigLine, isExist bool) error

SetKey set member variable via c.

If isExist is true, c is treated as ExistKey.
If isExist is false, c is treated as NotExistKey.

func (*Config) SetTypeCondition

func (cnf *Config) SetTypeCondition(c *ConfigLine, t types.BasicKind) error

func (Config) Validate

func (c Config) Validate() error

Validate check if configuration value is ok or not.

type ConfigLine

type ConfigLine struct {
	ClKey       interface{} `json:"key"` // string or []string
	ClValue     interface{} `json:"value,omitempty"`
	ClCondition string      `json:"condition,omitempty"`
}

ConfigLine represents each line of config file.

func NewConfigLineFromJson

func NewConfigLineFromJson(s string) (*ConfigLine, error)

NewConfigLineFromJson returns ConfigLine pointer via Json s.

type Keys

type Keys struct {
	Keys        []string
	FlattenKeys string
}

func (Keys) Compare

func (k Keys) Compare(ks Keys) bool

Compare compares k and ks.

func (Keys) GetValueFromMap

func (k Keys) GetValueFromMap(m map[interface{}]interface{}) (interface{}, bool)

GetValueFromMap returns the value from map m.

If the value is not found, it returns nil, false.

func (Keys) String

func (k Keys) String() string

String implements fmt.Stringer.

type TypeCondition

type TypeCondition struct {
	Keys             Keys
	Condition        Condition
	TypeConditionStr string
}

func (TypeCondition) String

func (tc TypeCondition) String() string

Jump to

Keyboard shortcuts

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