Go SDK for Serverless Workflow
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.
Table of Contents
Status
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) |
🚫 |
Releases
Getting Started
Installation
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
}
Parsing Workflow Files
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.
Programmatic Workflow Creation
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! 🙋
Contributing
We welcome contributions to improve this SDK. Please refer to the sections below for guidance on maintaining project standards.
Code Style
- 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
EditorConfig
For IntelliJ users, an example .editorconfig
file is available here. See the Jetbrains documentation for usage details.
Known Issues
MacOS Issue:
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