Documentation ¶
Index ¶
- Variables
- func EvaluateAddition(left, right reflect.Value) (reflect.Value, error)
- func EvaluateBitAnd(left, right reflect.Value) (reflect.Value, error)
- func EvaluateBitOr(left, right reflect.Value) (reflect.Value, error)
- func EvaluateDivision(left, right reflect.Value) (reflect.Value, error)
- func EvaluateEqual(left, right reflect.Value) (reflect.Value, error)
- func EvaluateGreaterThan(left, right reflect.Value) (reflect.Value, error)
- func EvaluateGreaterThanEqual(left, right reflect.Value) (reflect.Value, error)
- func EvaluateLesserThan(left, right reflect.Value) (reflect.Value, error)
- func EvaluateLesserThanEqual(left, right reflect.Value) (reflect.Value, error)
- func EvaluateLogicAnd(left, right reflect.Value) (reflect.Value, error)
- func EvaluateLogicOr(left, right reflect.Value) (reflect.Value, error)
- func EvaluateLogicSingle(left reflect.Value) (reflect.Value, error)
- func EvaluateModulo(left, right reflect.Value) (reflect.Value, error)
- func EvaluateMultiplication(left, right reflect.Value) (reflect.Value, error)
- func EvaluateNotEqual(left, right reflect.Value) (reflect.Value, error)
- func EvaluateSubtraction(left, right reflect.Value) (reflect.Value, error)
- func GetAttributeInterface(obj reflect.Value, fieldName string) (interface{}, error)
- func GetAttributeList(obj reflect.Value) ([]string, error)
- func GetAttributeType(obj reflect.Value, fieldName string) (reflect.Type, error)
- func GetAttributeValue(obj reflect.Value, fieldName string) (reflect.Value, error)
- func GetBaseKind(val reflect.Value) reflect.Kind
- func GetFunctionList(obj reflect.Value) ([]string, error)
- func GetFunctionParameterTypes(obj reflect.Value, methodName string) ([]reflect.Type, bool, error)
- func GetFunctionReturnTypes(obj reflect.Value, methodName string) ([]reflect.Type, error)
- func GetMapArrayValue(mapArray, selector interface{}) (ret interface{}, err error)
- func GetValueElem(val reflect.Value) reflect.Value
- func InvokeFunction(obj reflect.Value, methodName string, param []reflect.Value) (retval []reflect.Value, err error)
- func IsAttributeArray(objVal reflect.Value, fieldName string) (bool, error)
- func IsAttributeMap(obj reflect.Value, fieldName string) (bool, error)
- func IsAttributeNilOrZero(obj reflect.Value, fieldName string) (bool, error)
- func IsNumber(val reflect.Value) bool
- func IsStruct(val reflect.Value) bool
- func IsValidField(objVal reflect.Value, fieldName string) bool
- func ParseJSONRule(data []byte) (rs string, err error)
- func ParseJSONRuleset(data []byte) (rs string, err error)
- func ParseRule(rule *GruleJSON) (r string, err error)
- func SetAttributeInterface(obj reflect.Value, fieldName string, value interface{}) error
- func SetAttributeValue(objVal reflect.Value, fieldName string, value reflect.Value) error
- func SetMapArrayValue(mapArray, selector reflect.Value, newValue reflect.Value) (err error)
- func ValueToInterface(valueToConvert reflect.Value) interface{}
- type BytesResource
- type CloneRecord
- type CloneTable
- type EmbeddedResource
- type EmbeddedResourceBundle
- type FileResource
- type FileResourceBundle
- type GITResource
- type GITResourceBundle
- type GruleErrorReporter
- type GruleJSON
- type JSONResource
- type JSONResourceBundle
- type ReaderResource
- type Resource
- func NewBytesResource(bytes []byte) Resource
- func NewEmbeddedResource(source embed.FS, path string) Resource
- func NewFileResource(path string) Resource
- func NewJSONResourceFromResource(res Resource) (Resource, error)
- func NewReaderResource(reader io.Reader) Resource
- func NewURLResource(url string) Resource
- func NewURLResourceWithHeaders(url string, Header http.Header) Resource
- type ResourceBundle
- type URLResource
Constants ¶
This section is empty.
Variables ¶
var (
URLResourceTimeoutSecond = 1800 // 30 minutes
)
Functions ¶
func EvaluateAddition ¶ added in v1.2.1
EvaluateAddition will evaluate addition operation over two value
func EvaluateBitAnd ¶ added in v1.2.1
EvaluateBitAnd will evaluate Bitwise And operation over two value
func EvaluateBitOr ¶ added in v1.2.1
EvaluateBitOr will evaluate Bitwise Or operation over two value
func EvaluateDivision ¶ added in v1.2.1
EvaluateDivision will evaluate division operation over two value
func EvaluateEqual ¶ added in v1.2.1
EvaluateEqual will evaluate Equal operation over two value
func EvaluateGreaterThan ¶ added in v1.2.1
EvaluateGreaterThan will evaluate GreaterThan operation over two value
func EvaluateGreaterThanEqual ¶ added in v1.2.1
EvaluateGreaterThanEqual will evaluate GreaterThanEqual operation over two value
func EvaluateLesserThan ¶ added in v1.2.1
EvaluateLesserThan will evaluate LesserThan operation over two value
func EvaluateLesserThanEqual ¶ added in v1.2.1
EvaluateLesserThanEqual will evaluate LesserThanEqual operation over two value
func EvaluateLogicAnd ¶ added in v1.2.1
EvaluateLogicAnd will evaluate LogicalAnd operation over two value
func EvaluateLogicOr ¶ added in v1.2.1
EvaluateLogicOr will evaluate LogicalOr operation over two value
func EvaluateLogicSingle ¶ added in v1.6.3
EvaluateLogicSingle will evaluate single expression value
func EvaluateModulo ¶ added in v1.2.1
EvaluateModulo will evaluate modulo operation over two value
func EvaluateMultiplication ¶ added in v1.2.1
EvaluateMultiplication will evaluate multiplication operation over two value
func EvaluateNotEqual ¶ added in v1.2.1
EvaluateNotEqual will evaluate NotEqual operation over two value
func EvaluateSubtraction ¶ added in v1.2.4
EvaluateSubtraction will evaluate subtraction operation over two value
func GetAttributeInterface ¶
GetAttributeInterface will retrieve a members variable value as usable interface.
func GetAttributeList ¶
GetAttributeList will populate list of struct's public member variable.
func GetAttributeType ¶
GetAttributeType will return the type of a specific member variable
func GetAttributeValue ¶
GetAttributeValue will retrieve a members variable value.
func GetBaseKind ¶
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 ¶
GetFunctionList get list of functions in a struct instance
func GetFunctionParameterTypes ¶
GetFunctionParameterTypes get list of parameter types of specific function in a struct instance
func GetFunctionReturnTypes ¶
GetFunctionReturnTypes get list of return types of specific function in a struct instance
func GetMapArrayValue ¶ added in v1.6.0
func GetMapArrayValue(mapArray, selector interface{}) (ret interface{}, err error)
GetMapArrayValue get value of map, array atau slice by its selector value
func GetValueElem ¶ added in v1.13.0
GetValueElem will return the value val contains if val is of Kind Interface or Pointer
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 ¶
IsAttributeArray validate if a member variable is an array or a slice.
func IsAttributeMap ¶
IsAttributeMap validate if a member variable is a map.
func IsAttributeNilOrZero ¶
IsAttributeNilOrZero validate if a member variable is nil or zero.
func IsValidField ¶
IsValidField validates if an instance struct have a field with such name
func ParseJSONRule ¶ added in v1.10.0
ParseJSONRule accepts a byte array containing an rule in JSON format to be parsed into GRule syntax.
func ParseJSONRuleset ¶ added in v1.5.0
ParseJSONRuleset accepts a byte array containing an array of rules in JSON format to be parsed into GRule syntax.
func ParseRule ¶ added in v1.6.2
ParseRule Accepts a struct of GruleJSON rule and returns the parsed string of GRule.
func SetAttributeInterface ¶
SetAttributeInterface will try to set a member variable value with a value from an interface
func SetAttributeValue ¶
SetAttributeValue will try to set a member variable value with a new one.
func SetMapArrayValue ¶ added in v1.6.0
SetMapArrayValue will set a value into map array indicated by a selector
func ValueToInterface ¶
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 ¶ added in v1.4.0
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 ¶ added in v1.4.0
type CloneTable struct {
Records map[string]*CloneRecord
}
CloneTable will stores all meta information about AST object being cloned under one KnowledgeBase.
func NewCloneTable ¶ added in v1.4.0
func NewCloneTable() *CloneTable
NewCloneTable create new instance of CloneTable
func (*CloneTable) IsCloned ¶ added in v1.4.0
func (tab *CloneTable) IsCloned(astID string) bool
IsCloned will check if an AST object with identified astId has a clone.
func (*CloneTable) MarkCloned ¶ added in v1.4.0
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 EmbeddedResource ¶ added in v1.9.1
EmbeddedResource is a struct that will load an embedded file from an embed.FS struct. Note: EmbeddedResource is only available when using Go 1.16 or above
func (*EmbeddedResource) Load ¶ added in v1.9.1
func (res *EmbeddedResource) Load() ([]byte, error)
Load will load the resource into a byte array from the embedded source.
func (*EmbeddedResource) String ¶ added in v1.9.1
func (res *EmbeddedResource) String() string
type EmbeddedResourceBundle ¶ added in v1.9.1
type EmbeddedResourceBundle struct { // The base path for the embedded resources 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 Source embed.FS }
EmbeddedResourceBundle is a helper struct to load multiple embedded resources 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 NewEmbeddedResourceBundle ¶ added in v1.9.1
func NewEmbeddedResourceBundle(source embed.FS, basePath string, pathPattern ...string) *EmbeddedResourceBundle
NewEmbeddedResourceBundle creates new instance of EmbeddedResourceBundle struct source is the embed.FS from which to load files 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 (*EmbeddedResourceBundle) Load ¶ added in v1.9.1
func (bundle *EmbeddedResourceBundle) Load() ([]Resource, error)
Load all embedded file resources that located under BasePath that conform to the PathPattern.
func (*EmbeddedResourceBundle) MustLoad ¶ added in v1.9.1
func (bundle *EmbeddedResourceBundle) MustLoad() []Resource
MustLoad function is the same as Load with difference that it will panic if any error is raised
type FileResource ¶
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 ¶ added in v1.2.3
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 ¶ added in v1.2.4
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 ¶ added in v1.2.3
func (bundle *FileResourceBundle) Load() ([]Resource, error)
Load all file resources that locateed under BasePath that conform to the PathPattern.
func (*FileResourceBundle) MustLoad ¶ added in v1.2.3
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 ¶ added in v1.2.3
GITResource resource implementation that loaded from GIT
func (*GITResource) Load ¶ added in v1.2.3
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 ¶ added in v1.2.3
func (res *GITResource) String() string
String will state the resource url.
type GITResourceBundle ¶ added in v1.2.3
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 ¶ added in v1.2.4
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 NewGITResourceBundleWithAuth ¶ added in v1.11.0
func NewGITResourceBundleWithAuth(url string, user string, password string, pathPattern ...string) *GITResourceBundle
func (*GITResourceBundle) Load ¶ added in v1.2.3
func (bundle *GITResourceBundle) Load() ([]Resource, error)
Load will load the file from your git repository
func (*GITResourceBundle) MustLoad ¶ added in v1.2.3
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 GruleErrorReporter ¶ added in v1.8.6
type GruleErrorReporter struct { *antlr.DefaultErrorListener // Embed default which ensures we fit the interface Errors []error }
GruleErrorReporter is an implementation of ErrorListener interface by antlr. The purpose is to capture errors during lexer tokenization and parsing.
func (*GruleErrorReporter) AddError ¶ added in v1.8.6
func (c *GruleErrorReporter) AddError(err error)
AddError simply add an error into this reporter
func (*GruleErrorReporter) Error ¶ added in v1.8.6
func (c *GruleErrorReporter) Error() string
Error return an error text. This function is there for compatibility reason.
func (*GruleErrorReporter) HasError ¶ added in v1.8.6
func (c *GruleErrorReporter) HasError() bool
HasError check if this reporter has an error
func (*GruleErrorReporter) SyntaxError ¶ added in v1.8.6
func (c *GruleErrorReporter) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException)
SyntaxError call back which will be called upon parsing error
type GruleJSON ¶ added in v1.5.0
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 ¶ added in v1.5.0
type JSONResource struct {
// contains filtered or unexported fields
}
JSONResource will parse rules in JSON fromat from underlying resource provider.
func (*JSONResource) Load ¶ added in v1.5.0
func (jr *JSONResource) Load() ([]byte, error)
Load will load the underlying Resource and parse the JSON rules into standard GRule syntax.
func (*JSONResource) String ¶ added in v1.5.0
func (jr *JSONResource) String() string
String will state the resource source.
type JSONResourceBundle ¶ added in v1.5.0
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 ¶ added in v1.5.0
func (jrb *JSONResourceBundle) Load() ([]Resource, error)
Load will load the underlying ResourceBundle and parse the JSON rules into standard GRule syntax.
func (*JSONResourceBundle) MustLoad ¶ added in v1.5.0
func (jrb *JSONResourceBundle) MustLoad() []Resource
MustLoad operates the same as load except it will panic in the event of an error.
type ReaderResource ¶
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 Resource ¶
Resource should be implemented by any resource model so it can be loaded and parsed by the grule parser.
func NewBytesResource ¶
NewBytesResource will create a new Resource using a byte array.
func NewEmbeddedResource ¶ added in v1.9.1
NewEmbeddedResource will create a new instance of EmbeddedResource. source is an embed.FS struct path is the path to the embedded resource.
func NewFileResource ¶
NewFileResource will create a new Resource using a file located in path.
func NewJSONResourceFromResource ¶ added in v1.5.0
NewJSONResourceFromResource innstantiates a new JSON resource parser from an underlying Resource.
func NewReaderResource ¶
NewReaderResource will create a new Resource using a common reader.
func NewURLResource ¶
NewURLResource will create a new Resource using a resource as located in the url
type ResourceBundle ¶ added in v1.11.0
ResourceBundle is a helper struct to help load multiple resource at once.
func NewJSONResourceBundleFromBundle ¶ added in v1.5.0
func NewJSONResourceBundleFromBundle(bundle ResourceBundle) (ResourceBundle, error)
NewJSONResourceBundleFromBundle innstantiates a new bundled JSON resource parser from an underlying ResourceBundle.
type URLResource ¶
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.