pkg

package
v1.8.10 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: Apache-2.0, Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvaluateAddition

func EvaluateAddition(left, right reflect.Value) (reflect.Value, error)

EvaluateAddition will evaluate addition operation over two value

func EvaluateBitAnd

func EvaluateBitAnd(left, right reflect.Value) (reflect.Value, error)

EvaluateBitAnd will evaluate Bitwise And operation over two value

func EvaluateBitOr

func EvaluateBitOr(left, right reflect.Value) (reflect.Value, error)

EvaluateBitOr will evaluate Bitwise Or operation over two value

func EvaluateDivision

func EvaluateDivision(left, right reflect.Value) (reflect.Value, error)

EvaluateDivision will evaluate division operation over two value

func EvaluateEqual

func EvaluateEqual(left, right reflect.Value) (reflect.Value, error)

EvaluateEqual will evaluate Equal operation over two value

func EvaluateGreaterThan

func EvaluateGreaterThan(left, right reflect.Value) (reflect.Value, error)

EvaluateGreaterThan will evaluate GreaterThan operation over two value

func EvaluateGreaterThanEqual

func EvaluateGreaterThanEqual(left, right reflect.Value) (reflect.Value, error)

EvaluateGreaterThanEqual will evaluate GreaterThanEqual operation over two value

func EvaluateLesserThan

func EvaluateLesserThan(left, right reflect.Value) (reflect.Value, error)

EvaluateLesserThan will evaluate LesserThan operation over two value

func EvaluateLesserThanEqual

func EvaluateLesserThanEqual(left, right reflect.Value) (reflect.Value, error)

EvaluateLesserThanEqual will evaluate LesserThanEqual operation over two value

func EvaluateLogicAnd

func EvaluateLogicAnd(left, right reflect.Value) (reflect.Value, error)

EvaluateLogicAnd will evaluate LogicalAnd operation over two value

func EvaluateLogicOr

func EvaluateLogicOr(left, right reflect.Value) (reflect.Value, error)

EvaluateLogicOr will evaluate LogicalOr operation over two value

func EvaluateLogicSingle

func EvaluateLogicSingle(left reflect.Value) (reflect.Value, error)

EvaluateLogicSingle will evaluate single expression value

func EvaluateModulo

func EvaluateModulo(left, right reflect.Value) (reflect.Value, error)

EvaluateModulo will evaluate modulo operation over two value

func EvaluateMultiplication

func EvaluateMultiplication(left, right reflect.Value) (reflect.Value, error)

EvaluateMultiplication will evaluate multiplication operation over two value

func EvaluateNotEqual

func EvaluateNotEqual(left, right reflect.Value) (reflect.Value, error)

EvaluateNotEqual will evaluate NotEqual operation over two value

func EvaluateSubtraction

func EvaluateSubtraction(left, right reflect.Value) (reflect.Value, error)

EvaluateSubtraction will evaluate subtraction operation over two value

func GetAttributeInterface

func GetAttributeInterface(obj reflect.Value, fieldName string) (interface{}, error)

GetAttributeInterface will retrieve a members variable value as usable interface.

func GetAttributeList

func GetAttributeList(obj reflect.Value) ([]string, error)

GetAttributeList will populate list of struct's public member variable.

func GetAttributeType

func GetAttributeType(obj reflect.Value, fieldName string) (reflect.Type, error)

GetAttributeType will return the type of a specific member variable

func GetAttributeValue

func GetAttributeValue(obj reflect.Value, fieldName string) (reflect.Value, error)

GetAttributeValue will retrieve a members variable value.

func GetBaseKind

func GetBaseKind(val reflect.Value) reflect.Kind

GetBaseKind will try to obtain base obtainable kind of a value, so we know what method to call val.Int(), val.Uint(), etc.

func GetFunctionList

func GetFunctionList(obj reflect.Value) ([]string, error)

GetFunctionList get list of functions in a struct instance

func GetFunctionParameterTypes

func GetFunctionParameterTypes(obj reflect.Value, methodName string) ([]reflect.Type, bool, error)

GetFunctionParameterTypes get list of parameter types of specific function in a struct instance

func GetFunctionReturnTypes

func GetFunctionReturnTypes(obj reflect.Value, methodName string) ([]reflect.Type, error)

GetFunctionReturnTypes get list of return types of specific function in a struct instance

func GetMapArrayValue

func GetMapArrayValue(mapArray, selector interface{}) (ret interface{}, err error)

GetMapArrayValue get value of map, array atau slice by its selector value

func InvokeFunction

func InvokeFunction(obj reflect.Value, methodName string, param []reflect.Value) (retval []reflect.Value, err error)

InvokeFunction invokes a specific function in a struct instance, using parameters array

func IsAttributeArray

func IsAttributeArray(objVal reflect.Value, fieldName string) (bool, error)

IsAttributeArray validate if a member variable is an array or a slice.

func IsAttributeMap

func IsAttributeMap(obj reflect.Value, fieldName string) (bool, error)

IsAttributeMap validate if a member variable is a map.

func IsAttributeNilOrZero

func IsAttributeNilOrZero(obj reflect.Value, fieldName string) (bool, error)

IsAttributeNilOrZero validate if a member variable is nil or zero.

func IsNumber

func IsNumber(val reflect.Value) bool

IsNumber will check a value if its a number eg, int,uint or float

func IsStruct

func IsStruct(val reflect.Value) bool

IsStruct validates if an instance is struct or pointer to struct

func IsValidField

func IsValidField(objVal reflect.Value, fieldName string) bool

IsValidField validates if an instance struct have a field with such name

func ParseJSONRuleset

func ParseJSONRuleset(data []byte) (rs string, err error)

ParseJSONRuleset accepts a byte array containing an array of rules in JSON format to be parsed into GRule syntax.

func ParseRule

func ParseRule(rule *GruleJSON) (r string, err error)

ParseRule Accepts a struct of GruleJSON rule and returns the parsed string of GRule.

func SetAttributeInterface

func SetAttributeInterface(obj reflect.Value, fieldName string, value interface{}) error

SetAttributeInterface will try to set a member variable value with a value from an interface

func SetAttributeValue

func SetAttributeValue(objVal reflect.Value, fieldName string, value reflect.Value) error

SetAttributeValue will try to set a member variable value with a new one.

func SetMapArrayValue

func SetMapArrayValue(mapArray, selector reflect.Value, newValue reflect.Value) (err error)

SetMapArrayValue will set a value into map array indicated by a selector

func ValueToInterface

func ValueToInterface(v reflect.Value) interface{}

ValueToInterface will try to obtain an interface to a speciffic value. it will detect the value's kind.

Types

type BytesResource

type BytesResource struct {
	Bytes []byte
}

BytesResource is a struct that will hold the byte array data

func (*BytesResource) Load

func (res *BytesResource) Load() ([]byte, error)

Load will load the resource into byte array.

func (*BytesResource) String

func (res *BytesResource) String() string

String will state the resource byte array.

type CloneRecord

type CloneRecord struct {
	OriginAstID    string
	CloneAstID     string
	OriginInstance interface{}
	CloneInstance  interface{}
}

CloneRecord contains information about all AST versions, instance, their cloned version and cloned instance.

type CloneTable

type CloneTable struct {
	Records map[string]*CloneRecord
}

CloneTable will stores all meta information about AST object being cloned under one KnowledgeBase.

func NewCloneTable

func NewCloneTable() *CloneTable

NewCloneTable create new instance of CloneTable

func (*CloneTable) IsCloned

func (tab *CloneTable) IsCloned(astID string) bool

IsCloned will check if an AST object with identified astId has a clone.

func (*CloneTable) MarkCloned

func (tab *CloneTable) MarkCloned(originAst, cloneAst string, origin, clone interface{})

MarkCloned will record that an Ast object are now been cloned, so all other cloned object should reference to the newly cloned Ast object

type FileResource

type FileResource struct {
	Path  string
	Bytes []byte
}

FileResource is a struct that will hold the file path and readed data bytes.

func (*FileResource) Load

func (res *FileResource) Load() ([]byte, error)

Load will load the resource into byte array. The load byte array will be cached by the FileResource. So Calling Load multiple time will only load the file once on the first call. If you wish to reload the file, simply create new instance using NewFileResource function.

func (*FileResource) String

func (res *FileResource) String() string

String will state the resource file path.

type FileResourceBundle

type FileResourceBundle struct {
	// The base path where all the
	BasePath string
	// List Glob like file pattern.
	// *.grl           <- matches abc.grl but not /anyfolder/abc.grl
	// **/*.grl        <- matches abc/def.grl or abc/def/ghi.grl or abc/def/.grl
	// /abc/**/*.grl   <- matches /abc/def.grl or /abc/def/ghi.drl
	PathPattern []string
}

FileResourceBundle is a helper struct to load multiple files all at once by specifying the root location of the file and the file pattern to look for. It will look into sub-directories for the file with pattern matching.

func NewFileResourceBundle

func NewFileResourceBundle(basePath string, pathPattern ...string) *FileResourceBundle

NewFileResourceBundle creates new instance of FileResourceBundle struct basePath denotes the directory location where the file is located. pathPattern are list of paths that filters the files. Its important that the pattern will include the base path as it filter. For example, if the base path is "/some/base/path" The pattern to accept all GRL file is "/some/base/path/**/*.grl". This will accept all *.grl files under /some/base/path and its directories.

func (*FileResourceBundle) Load

func (bundle *FileResourceBundle) Load() ([]Resource, error)

Load all file resources that locateed under BasePath that conform to the PathPattern.

func (*FileResourceBundle) MustLoad

func (bundle *FileResourceBundle) MustLoad() []Resource

MustLoad function is the same as Load with difference that it will panic if any error is raised

type GITResource

type GITResource struct {
	URL   string
	Path  string
	Bytes []byte
}

GITResource resource implementation that loaded from GIT

func (*GITResource) Load

func (res *GITResource) Load() ([]byte, error)

Load will load the resource into byte array. This implementation will no re-load resources from git when this method is called, it simply return the loaded data.

func (*GITResource) String

func (res *GITResource) String() string

String will state the resource url.

type GITResourceBundle

type GITResourceBundle struct {
	// GIT Repository HTTPS URL
	URL string
	// The Ref name to checkout, if you dont know, let it empty
	RefName string
	// The remote name. IF you left it empty, it will use origin
	Remote string
	// Specify the user name if your repository requires user/password authentication
	User string
	// Password for authentication
	Password string
	// File path pattern to load in your git. The path / is the root on the repository.
	PathPattern []string
}

GITResourceBundle is a helper struct to load multiple files from GIT all at once by specifying the necessary information needed to communicate to the GIT server. It will look into sub-directories, in the git, for the file with pattern matching.

func NewGITResourceBundle

func NewGITResourceBundle(url string, pathPattern ...string) *GITResourceBundle

NewGITResourceBundle will create a new instance of GITResourceBundle url is the GIT http/https url. pathPattern are list of file pattern (glob) to filter files located in the repository

func (*GITResourceBundle) Load

func (bundle *GITResourceBundle) Load() ([]Resource, error)

Load will load the file from your git repository

func (*GITResourceBundle) MustLoad

func (bundle *GITResourceBundle) MustLoad() []Resource

MustLoad is the same as Load, the difference is it will panic if an error is raised during fetching resources.

type GruleJSON

type GruleJSON struct {
	Name        string        `json:"name"`
	Description string        `json:"desc"`
	Salience    int           `json:"salience"`
	When        interface{}   `json:"when"`
	Then        []interface{} `json:"then"`
}

GruleJSON represents a rule in JSON format

type JSONResource

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

JSONResource will parse rules in JSON fromat from underlying resource provider.

func (*JSONResource) Load

func (jr *JSONResource) Load() ([]byte, error)

Load will load the underlying Resource and parse the JSON rules into standard GRule syntax.

func (*JSONResource) String

func (jr *JSONResource) String() string

String will state the resource source.

type JSONResourceBundle

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

JSONResourceBundle will parse a set of rules in JSON format from an underlying bundle resource provider.

func (*JSONResourceBundle) Load

func (jrb *JSONResourceBundle) Load() ([]Resource, error)

Load will load the underlying ResourceBundle and parse the JSON rules into standard GRule syntax.

func (*JSONResourceBundle) MustLoad

func (jrb *JSONResourceBundle) MustLoad() []Resource

MustLoad operates the same as load except it will panic in the event of an error.

type ReaderResource

type ReaderResource struct {
	Reader io.Reader
}

ReaderResource is a struct that will hold the reader instance.

func (*ReaderResource) Load

func (res *ReaderResource) Load() ([]byte, error)

Load will load the resource into byte array.

func (*ReaderResource) String

func (res *ReaderResource) String() string

String will state the resource source.

type ResouceBundle

type ResouceBundle interface {
	Load() ([]Resource, error)
	MustLoad() []Resource
}

ResouceBundle is a helper struct to help load multiple resource at once.

func NewJSONResourceBundleFromBundle

func NewJSONResourceBundleFromBundle(bundle ResouceBundle) ResouceBundle

NewJSONResourceBundleFromBundle innstantiates a new bundled JSON resource parser from an underlying ResourceBundle.

type Resource

type Resource interface {
	Load() ([]byte, error)
	String() string
}

Resource should be implemented by any resource model so it can be loaded and parsed by the grule parser.

func NewBytesResource

func NewBytesResource(bytes []byte) Resource

NewBytesResource will create a new Resource using a byte array.

func NewFileResource

func NewFileResource(path string) Resource

NewFileResource will create a new Resource using a file located in path.

func NewJSONResourceFromResource

func NewJSONResourceFromResource(res Resource) Resource

NewJSONResourceFromResource innstantiates a new JSON resource parser from an underlying Resource.

func NewReaderResource

func NewReaderResource(reader io.Reader) Resource

NewReaderResource will create a new Resource using a common reader.

func NewURLResource

func NewURLResource(url string) Resource

NewURLResource will create a new Resource using a resource as located in the url

type URLResource

type URLResource struct {
	URL   string
	Bytes []byte
}

URLResource is a struct that will hold the byte array data and URL source

func (*URLResource) Load

func (res *URLResource) Load() ([]byte, error)

Load will load the resource into byte array. This resource will cache the obtained result byte arrays. So calling this function multiple times only call the URL once at the first time. If you want to refresh the load, you simply create a new instance of URLResource using NewURLResource

func (*URLResource) String

func (res *URLResource) String() string

String will state the resource url.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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