p := ograph.NewPipeline()
e := ograph.NewElement("cmd").UseFactory(ogimpl.CMD).
Params("Cmd", []string{"go", "version"})
// register and run the node which exec go version
p.Register(e).Run(context.TODO(), nil)
Name | Required | Meaning | Type | Example |
---|
Cmd | ✔ | cmd to exec | []string | [“go”,“version”] |
Env | ✗ | exec env | []string | [“key=value”] |
Dir | ✗ | working directory | string | “/root” |
Cmd parameter format: [“commandName/path”, “parameter1”, “parameter2”, …]
Use the OGRAPH_ALLOW_CMD_LIST environment variable to limit executable commands
Linux
export OGRAPH_ALLOW_CMD_LIST=ls,cat
state := ograph.NewState()
state.Set("time", time.Now())
p := ograph.NewPipeline()
e := ograph.NewElement("req").UseFactory(ogimpl.HttpReq).
Params("Method", "POST").
Params("Url", "http://localhost:8080/ping").
// Render body as:
// Send-Time: 2024-08-03 10:10:20.0873372 +0800 CST m=+0.002574001
Params("BodyTpl", `Send-Time: {{GetState "time"}}`)
p.Register(e).Run(context.Background(), state)
Name | Required | Meaning | Type | Example |
---|
Method | ✔ | http method | string | POST |
Url | ✔ | http url | string | http://localhost:8080/ping |
ContentType | ✗ | content-type | string | application/json |
Body | ✗ | request body | string | hello |
BodyTpl | ✗ | body template | string | hello, i am {{GetState “name”}} |
Currently supports only GET and POST request methods.
When rendering the request body with a template, the GetState function can be used to extract the execution state values. The state value must be publicly accessible (i.e., the key needs to be of string type, not a private type).
p := ograph.NewPipeline()
a := ograph.NewElement("Assert").Apply(ogimpl.AssertOp("i==1"))
p.Register(a)
s := ograph.NewState()
s.Set("i", 1) // if set with other value, the assertion fails, then the pipeline will also fail
p.Run(context.TODO(), s)
Name | Required | Meaning | Type | Example |
---|
AssertExpr | ✔ | Assert Expr | string | “i==1” |
The state value must be publicly accessible (i.e., the key needs to be of string type, not a private type).