Skip to content

Introducing Golang Code Example documentation to use this Rulio Engine#65

Open
HemantJoshi11 wants to merge 1 commit intoComcast:masterfrom
HemantJoshi11:Golang_Code_Example
Open

Introducing Golang Code Example documentation to use this Rulio Engine#65
HemantJoshi11 wants to merge 1 commit intoComcast:masterfrom
HemantJoshi11:Golang_Code_Example

Conversation

@HemantJoshi11
Copy link

Golang Code Example documentation to use this Rulio Engine

This code commit contain

  1. Simple Golang client to use rulio engine.
  2. Following use cases has been added
    • Add a Fact
    • Search a Fact
    • List Rules
    • Process an Event

@HemantJoshi11
Copy link
Author

@jsccast pls review.

@decibelcooper
Copy link
Contributor

Forgive me as I am only an observer here, not a maintainer, but perhaps the use of the word "client" is not appropriate here?

The code base has a reference HTTP API, and my thought in seeing this PR was that you were offering an example client for that API. Perhaps a more appropriate way to present this is as an example engine.

Copy link
Member

@jsccast jsccast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

The biggest requested changes are to reference/use existing code rather than copy/pasting code. See sys.System.SearchFacts and all those other important System methods for examples. Maybe you don't want to use those methods for some reason. If so, what's the rationale?

Thanks again for the PR.


### Starting
To run execute go run main.go
.../rulio\examples\go-client>go run main.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those backlashes are confusing (and won't work on non-Windows platforms).

Also that line should probably be marked up as code. Similarly for the code in the line above.


```
### Sample output
```Shell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text in this block isn't shell input. Maybe just drop the Shell?

{"id":"ID is: ","result":"498a3b4e-5c44-4942-bab3-9380f8361bff Work is: ""}%!(EXTRA *core.FindRules=&{map[age:30 city:London code:SEC-3423 name:John] complete [0xc0002fe280] [city Lond
on]})
Result is: {
"event": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This JSON should probably be in Markdown JSON code block:

{"like":"this"}

GenericEnvConfig
}

type EngineEnvConfig struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we shouldn't repeat this kind of struct here when we have (for example) sys. SystemConfig. Can you refactor to use existing structs?

}

type EngineEnvConfig struct {
// "linear (or indexed) state?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see guidelines for commenting Go code.

"time"
)

type EnginePoc struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to refactor this code to use sys.System? Looks like you are duplicating a lot of code.

return &EnginePoc{Ctx: ctx, Service: engineService}, nil
}

type BashActionInterpreter struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably shouldn't duplicate code like this. Can you just reference/use existing types instead of copy/pasting code?

"time"
)

type Service struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this Service different from service.Service? A comment there would be helpful.

package service

import (
"encoding/json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should probably be organized by standard packages, packages in this repo, and third-party packages. You can use blank lines to separate those groups of imports.

Stopper func(*core.Context, time.Duration) error
}

func (s *Service) SearchFact(ctx *core.Context, m map[string]interface{}) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why repeat all of this implementation when we have sys.System.SearchFacts? Can you refactor to use existing code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants