The Go SDK for Serverless Workflow provides the specification types defined by the Serverless Workflow DSL in Go, making it easy to parse, validate, and interact with workflows.
The current status of features implemented in the SDK is listed below:
Feature | Status |
---|---|
Parse workflow JSON and YAML definitions | ✔️ |
Programmatically build workflow definitions | ✔️ |
Validate workflow definitions (Schema) | ✔️ |
Validate workflow definitions (Integrity) | 🚫 |
Generate workflow diagram (SVG) | 🚫 |
Latest Releases | Conformance to Spec Version |
---|---|
v1.0.0 | v0.5 |
v2.0.1 | v0.6 |
v2.1.2 | v0.7 |
v2.4.3 | v0.8 |
v3.0.0 | v1.0.0 |
To use the SDK in your Go project, run the following command:
$ go get github.com/serverlessworkflow/sdk-go/v3
This will update your go.mod
file to include the Serverless Workflow SDK as a dependency.
Import the SDK in your Go file:
import "github.com/serverlessworkflow/sdk-go/v3/model"
You can now use the SDK types and functions, for example:
package main
import (
"github.com/serverlessworkflow/sdk-go/v3/builder"
"github.com/serverlessworkflow/sdk-go/v3/model"
)
func main() {
workflowBuilder := New().
SetDocument("1.0.0", "examples", "example-workflow", "1.0.0").
AddTask("task1", &model.CallHTTP{
TaskBase: model.TaskBase{
If: &model.RuntimeExpression{Value: "${condition}"},
},
Call: "http",
With: model.HTTPArguments{
Method: "GET",
Endpoint: model.NewEndpoint("http://example.com"),
},
})
workflow, _ := builder.Object(workflowBuilder)
// use your models
}
The Serverless Workflow Specification supports YAML and JSON files. Use the following example to parse a workflow file into a Go data structure:
package main
import (
"github.com/serverlessworkflow/sdk-go/v3/model"
"github.com/serverlessworkflow/sdk-go/v3/parser"
)
func ParseWorkflow(filePath string) (*model.Workflow, error) {
workflow, err := parser.FromFile(filePath)
if err != nil {
return nil, err
}
return workflow, nil
}
This Workflow
structure can then be used programmatically in your application.
Support for building workflows programmatically is planned for future releases. Stay tuned for updates in upcoming versions.
Join the conversation and connect with other contributors on the CNCF Slack. Find us in the #serverless-workflow-sdk
channel and say hello! 🙋
We welcome contributions to improve this SDK. Please refer to the sections below for guidance on maintaining project standards.
- Use
goimports
for import organization. - Lint your code with:
make lint
To automatically fix lint issues, use:
make lint params=--fix
Example lint error:
$ make lint
make addheaders
make fmt
./hack/go-lint.sh
util/floatstr/floatstr_test.go:19: File is not `goimports`-ed (goimports)
"k8s.io/apimachinery/pkg/util/yaml"
make: *** [lint] Error 1
For IntelliJ users, an example .editorconfig
file is available here. See the Jetbrains documentation for usage details.
On MacOS, you might encounter the following error:
goimports: can't extract issues from gofmt diff output
To resolve this, install diffutils
:
brew install diffutils